Displaying the data from the select query in a particular format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Displaying the data from the select query in a particular format
# 1  
Old 12-05-2007
Displaying the data from the select query in a particular format

Hi,

I have a shell script that returns 10 records for the column Name and age from a select query. Where when i store those data in retrieve_list.txt file i need to store the data in a particular format like:-

$Jason$30
$Bill$23
$Roshan$25

Here is my script:

1) database_retrieve_script.sh
-------------------------------


#!/bin/ksh

LOGFILE="databaseRetrieve.log"
USER="myuser"
PASS="mypass"
SID="sampledb"

sqlplus -s ${USER}/${PASS}@${SID} << EOF >${LOGFILE} 2>&1
whenever oserror exit 98;
whenever sqlerror exit 99;
@retriveData.sql
exit 140;
EOF
SQL_DATA="$?"
if [ "$?" -ne 140 ]
then
echo "Connection error (Oracle down?)"
else
echo "Connection estabilished, script executed."
${SQL_DATA} > retrieve_list.txt
fi


2) retriveData.sql
------------------------
#!/bin/ksh

select * from retrieveTable;

Here the script will get the whole data and won't store it
in the above format.I want the data to be stored in the above format.Pls. do help me in this.It is urgent...

Thanks
# 2  
Old 12-05-2007
kindly change your retriveData.sql

as follows,

HTML Code:
select '$'||ColumnName1||'$'||ColumnName2 from <retrieveTable>;
# 3  
Old 12-06-2007
Thanks Manas... But how i will get the data in the format i want..Pls. do help me in this.
# 4  
Old 12-06-2007
Pls. do reply on this to get the data in above format.
# 5  
Old 12-06-2007
U can use the the query as provided in ur sql file "@retriveData.sql" and then call the shell script.

- If there are some error/exception or whatever is the difference in the output vs expected, please specify
# 6  
Old 12-07-2007
Thats right... I can get the data(Name,Age) from the select query but i need to organize the data in a particular format. Like:

$Jason$30
$Bill$23
$Roshan$25

and save those data into a file. Here my question is that how to organize the data in the above format after getting the data from the query? Pls. do help me...
# 7  
Old 12-07-2007
Pls. do reply i am finding it difficult to store the data in above format in a .txt file..Pls. do help me in this. It is urgent...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in executing select query from perl script

Hi, I have a perl snippet that call a select query with a bind variable,when i compile the script I'm unable to get the query output. The same query when i fire in sqlplus fetches few rows. The query takes bit time to fetch results in sqlplus. my $getaccts = $lda->prepare("select distinct ... (1 Reply)
Discussion started by: rkrish
1 Replies

2. Shell Programming and Scripting

Displaying output in the tabular format

Hi I want to display the following input data into the tabular format as shown in the output. Input.txt: Following jobs are in pending state for more than 10 minutes: JOB_ID JOB_SUBMIT_ID MAHAR 784308 PUNJA 109367 Following jobs are running for longer time: JOB_ID... (1 Reply)
Discussion started by: dats
1 Replies

3. UNIX for Advanced & Expert Users

mysql select query optimization..

hi.. i need to optimize my select query .. my situation is like this .. i have 15 lac recors in my table.. the following query takes nine seconds to give the required output.. SELECT max(ah.AUC_AMT), SUBSTRING_INDEX(GROUP_CONCAT(SUBSTRING_INDEX(ah.AUC_CUS_NAME,'@',1) order by AUC_AMT... (1 Reply)
Discussion started by: senkerth
1 Replies

4. Shell Programming and Scripting

mysql select query optimization..

hi.. i need to optimize my select query .. my situation is like this .. i have 15 lac recors in my table.. the following query takes nine seconds to give the required output.. SELECT max(ah.AUC_AMT), SUBSTRING_INDEX(GROUP_CONCAT(SUBSTRING_INDEX(ah.AUC_CUS_NAME,'@',1) order by AUC_AMT... (0 Replies)
Discussion started by: senkerth
0 Replies

5. Shell Programming and Scripting

Select query implement in a shell

I have been asked to create a shell script that accepts a number of SQL select queries as input, runs them in sequence, spools the output to an EXCEL workbook, where, each worksheet is an output of a Select statement run above. The workbook should be in a .XLS format. If a particular select... (2 Replies)
Discussion started by: ShellNovice1
2 Replies

6. Shell Programming and Scripting

Displaying the output in the tabular Format

Hi, I have a file which contains the data in the below format and need to develop a script which will give the output in the tabular format. Could you please advice me. Folder: Workflow: version . Workflow run status: Workflow run error code: Schedule time: Workflow run type: ... (2 Replies)
Discussion started by: kandi.reddy
2 Replies

7. Shell Programming and Scripting

Redirect Postgresql Select Query to Variable

How to redirect postgresql select query to a variable using shell scripts? I tried to use psql -c "select ip from servers" db | egrep '+\.+\+\+' | sed 's/^ *\(.*\) *$/\1/' Output: 10.10.10.180 10.10.10.181 It display ip addresses from the databasem, but how could i redirect the... (3 Replies)
Discussion started by: uativan
3 Replies

8. Shell Programming and Scripting

how to convert the result of the select query to comma seperated data - urgent pls

how to convert the result of the select query to comma seperated data and put in a .csv file using korn shell. Pls help me as its very urgent. Thanks, Hema. (1 Reply)
Discussion started by: Hemamalini
1 Replies

9. Shell Programming and Scripting

Need Help (Select query)

Dear All, This may sound a simple query but a non technical person like me is not able to do it, So please help me out. I m using Unix... isql I jst wanted to do something like following select * from xyz where ID= xxxxxxxx (8 digit ID) Here if i put single 8 digit ID then the... (5 Replies)
Discussion started by: topgear1000cc
5 Replies

10. Shell Programming and Scripting

How to store the data retrived by a select query into variables?

Hi Friends, Can u please help mw with the following query . I need to run a database sql statement to select particular fields from a table.I need to store the retrieved filed values into variables so that i can print it in a specific format. But the particular select query retrieves more... (12 Replies)
Discussion started by: jisha
12 Replies
Login or Register to Ask a Question