Sending sqlplus output to a shell variable | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Sending sqlplus output to a shell variable

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-17-2012
beginer314 beginer314 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 17 December 2012, 2:37 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Sending sqlplus output to a shell variable

I am trying to import a sqlplus output into a shell variable but it doesnt seem to be working.

Code:
set -x
export DEPENDENT_CR_NO=`sqlplus -s /nolog <<EOF
conn username/passwd
set heading off
select dependency from custom_patches where patch_name='PATCH.zip';
exit;
EOF`
echo $DEPENDENT_CR_NO

if [[ $DEPENDENT_CR_N0 = '' ]] then
echo "there is no dependency"
else
echo "DEPENDENCY IS $DEPENDENT_CR_N0"
fi

Below is the output from the above script


Code:
+ sqlplus -s /nolog
+ 0<< \EOF
conn username/psswd
set heading off
select dependency from custom_patches where patch_name='PATCH.zip';
exit;
EOF
+ DEPENDENT_CR_NO=$'\n56240; 56242'
+ export DEPENDENT_CR_NO
+ echo '56240;' 56242
56240; 56242
+ [[ '' == '' ]]
+ echo 'there is no dependency'
there is no dependency

I am not sure why $DEPENDENT_CR_NO is coming up null in the if loop.

Thanks

Last edited by Scott; 12-17-2012 at 02:10 PM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 12-17-2012
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 23 August 2014, 10:12 AM EDT
Location: Zürich
Posts: 8,472
Thanks: 330
Thanked 1,046 Times in 913 Posts
Hi.

You have DEPENDENT_CR_NO (with Oh) and DEPENDENT_CR_N0 (with zero).


Code:
export DEPENDENT_CR_NO=`sqlplus -s /nolog <<EOF
conn username/passwd
set heading off
select dependency from custom_patches where patch_name='PATCH.zip';
exit;
EOF`
echo $DEPENDENT_CR_NO

if [[ $DEPENDENT_CR_N0 = '' ]] then
...

Your test will also fail because without set feedback off, the variable will always contain text.
The Following User Says Thank You to Scott For This Useful Post:
beginer314 (12-17-2012)
Sponsored Links
    #3  
Old 12-17-2012
beginer314 beginer314 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 17 December 2012, 2:37 PM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks Scott, that was a stupid mistake i made. Thanks for the quick reply.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sending Sed/Echo output to Variable nitrobass24 Shell Programming and Scripting 4 08-28-2012 04:25 PM
Log sqlplus output from Shell WhoDatWhoDer Shell Programming and Scripting 2 06-15-2011 11:26 AM
store sqlplus output in variable murtymvvs Shell Programming and Scripting 1 12-04-2010 12:46 PM
error in passing a variable to sqlplus from a shell script kripssmart Shell Programming and Scripting 3 07-08-2008 07:01 PM
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 02:31 PM



All times are GMT -4. The time now is 11:19 AM.