The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help (Select query) topgear1000cc Shell Programming and Scripting 5 02-12-2008 07:22 AM
Displaying the data from the select query in a particular format sachin.tendulka Shell Programming and Scripting 15 12-11-2007 08:44 AM
Extract numbers from a string and store in variables davewg Shell Programming and Scripting 6 11-14-2007 05:22 AM
How to store query multiple result in shell script variable(Array) div_Neev Shell Programming and Scripting 4 11-06-2007 08:10 PM
Select a portion of file based on query vanand420 Shell Programming and Scripting 14 10-31-2006 04:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-17-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
Arrow 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 than 1 row .I have redirected the result of the query to a temporary text file.Lets say there are 10 rows retrieved. These retrieved values(filed_name value) are written into say 1.txt.
Now 1.txt looks some what like this :

fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value fld_name value

I thought of using a grep command to get the values and store it in a variable.But the format of this text file makes it impossible.

Can please help me to put the data as below in 1.txt

fld_name value
fld_name value
fld_name value
fld_name value
fld_name value
fld_name value

or
When we run a select statement the rows are retrieved in the below format :
fld_name value
fld_name value
fld_name value

fld_name value
fld_name value
fld_name value


fld_name value
fld_name value
fld_name value


3 rows retrieved

Is there any way to store exactly this way to 1.txt?

Thanks in advance
Jisha
  #2 (permalink)  
Old 01-17-2008
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
use spool

You can write the following statement on the SQL prompt, before the Select query


Quote:
SQL>spool 1.txt;
SQL> select ....
SQL> spool off;
  #3 (permalink)  
Old 01-17-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
Quote:
Originally Posted by gauravgoel View Post
You can write the following statement on the SQL prompt, before the Select query
Thank you gauravgoel. .
My script is like this :

`isqlrf <database_name> - <<EOFSQL
select ....
from .....
where .....;
EOFSQl`

How i put the output of the above query was as below:

values=`isqlrf <database_name> - <<EOFSQL
select ....
from .....
where .....;
EOFSQl`

echo $values > 1.txt

I dont know anything about spools.Do u think my way of approach is correct?

Many Thanks
Jisha
  #4 (permalink)  
Old 01-17-2008
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
as I mentioned before your select put

spool 1.txt

and after select put

spool off;


and after this you neednot redirect the output to 1.txt
  #5 (permalink)  
Old 01-17-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
I did like this :
`isqlrf <database_name> - spool 1.txt;<<EOFSQL
select ....
from .....
where .....;
spool off;
EOFSQl`

I executed & nothing happened .The file was also not created.

Thanks
Jisha
  #6 (permalink)  
Old 01-17-2008
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
try like this

`isqlrf <database_name>;<<EOFSQL
spool 1.txt
select ....
from .....
where .....;
spool off;
EOFSQl`


you may need to tweak it around a bit,
Sorry cant check right now for you as dont have access to UNIX system right now
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0