The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in For Loop The Observer Shell Programming and Scripting 2 05-28-2008 03:43 AM
for loop problem namishtiwari Shell Programming and Scripting 5 01-25-2008 12:58 PM
loop problem maskot Shell Programming and Scripting 1 05-25-2007 05:10 AM
Problem with for loop/sed ? chiru_h Shell Programming and Scripting 2 08-27-2006 12:55 PM
problem with while loop mridula High Level Programming 1 12-11-2005 11:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-21-2006
nandajk nandajk is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 1
Post How to pass values from select statement to a shell script variable

Connected to oracle database
sqlplus << EOF
$CONNECTSTR
set heading off
set trimspool on
set feedback off

select ID,DATE from sysadm.TEST where VALUE = 'A' order by ID;

value_id = ID
value_date = DATE
EOF

1. Is it possible to reference the values, ID,DATE in unix shell script.
2. Is it possible to loop through the select statement incase the select statement returns 10 rows.
3. if the only option is writting the values from select statement to a flat file, then the above select statement writes the 10 rows in the flat file.
  #2 (permalink)  
Old 06-21-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Try piping the whole select statement to a 'while read ...'. I think that should work.
  #3 (permalink)  
Old 05-02-2007
credit85 credit85 is offline
Registered User
  
 

Join Date: May 2007
Posts: 10
Quote:
Originally Posted by blowtorch
Try piping the whole select statement to a 'while read ...'. I think that should work.
hi,

i tried piping the whole thing to while read but there are still some errors:

#construct SQL statement

{$DCITS_SQL << EOF
set head off
select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN;
exit
EOF
}|while read line

do
if ["$line"]#check if line is not null
then
#if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo '$fin,$name,$gway' >> $final
endif
done

please help? thanks!
  #4 (permalink)  
Old 05-02-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
"if" syntax

Check the 'if' syntax. There should be a space before and after the "line".

Code:
if [ "$line" ]
then
...
fi

Use 'fi' instead of 'endif'
Please post any errors you get for that would give a clue where the issue is.
  #5 (permalink)  
Old 05-02-2007
credit85 credit85 is offline
Registered User
  
 

Join Date: May 2007
Posts: 10
Quote:
Originally Posted by ranj@chn
Check the 'if' syntax. There should be a space before and after the "line".

Code:
if [ "$line" ]
then
...
fi

Use 'fi' instead of 'endif'
Please post any errors you get for that would give a clue where the issue is.
hi,

so glad to see ur reply

here's my error

Missing }
}: Command not found
while: Expression syntax


thanks!
  #6 (permalink)  
Old 05-02-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
code changes

The changes are marked in bold.

Code:
{
$DCITS_SQL << EOF
set head off
select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN;
exit
EOF
}|while read line
do
if [ "$line" ] #check if line is not null
then 
#if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3" 
echo "$fin,$name,$gway" >> $final #changing single quotes to double
fi   # not endif
done

  #7 (permalink)  
Old 05-02-2007
credit85 credit85 is offline
Registered User
  
 

Join Date: May 2007
Posts: 10
Problem with while loop and SQL

hi,

i am trying to do a unix script and this is my first time getting in touch with unix.

i am trying to query and execute the following:
====================================================

touch $dir/emailList.txt
set final = $dir/emailList.txt

#construct SQL statement

$DCITS_SQL << SQLSTAT
set line=(select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN);
SQLSTAT

while read ($line)

#pipe the output to while read
do
if ["$line"]#check if line is not null
then
#if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo '$fin,$name,$gway' >> $final
endif
done
=======================================================
i keep having the error "line=undefined variable". any one know whats wrong with the above? many thanks in advance!
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 04:18 AM.


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