The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SQLPLUS unable to execte query automatically from solaris script jyotisree SUN Solaris 2 08-11-2008 03:03 AM
Oracle Query results to be stored in variables ashokjaysiv Shell Programming and Scripting 1 03-24-2008 01:37 AM
SQLPLUS and update statements using bind variables Nomaad UNIX for Advanced & Expert Users 3 08-19-2007 12:55 AM
sql query results in unix shell script skyineyes UNIX for Dummies Questions & Answers 1 06-20-2007 07:56 AM
How to pass Shell variables to sqlplus use them as parameters Jtrinh Shell Programming and Scripting 1 07-13-2005 01:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-01-2008
Registered User
 

Join Date: Oct 2007
Location: India
Posts: 28
Exclamation Set shell variables from SQLPLUS query results

Hi All,

I needed to get the result of two sqlplus queris into shell variables.

After days of looking for the ultimate solution to this problem.. i found this...
Code:
sqlplus -s USER/PASS@DB <<EOF | awk '{if(NR==1) printf("%s ", $1); if(NR==2) printf("%s ",
$1);}' | read VAR1 VAR2
set head off pagesize 0 echo off verify off feedback off
select name from v$database
/
select log_mode from v$database
/
EOF
from here...

I did not understand the logic used in the above peice of code. As far I was concerned, my objective was achieved. But then I saw perils of under-understanding! Knowledge shouldn't be a mission, it should be a journey!

The problem I am facing now is that, I now need to get just one value out of the sqlplus connection. So, i just simply tried..
Code:
sqlplus -s USER/PASS@DB <<EOF | awk '{if(NR==1) printf("%s ", $1);' | read VAR1
set head off pagesize 0 echo off verify off feedback off
select name from v$database
/
EOF
But to no avail.. anybody willing to help me out on this, will be heartfully appreciated.

Thanks!
Pranav
Reply With Quote
Forum Sponsor
  #2  
Old 09-01-2008
dj -------
 

Join Date: Feb 2007
Location: Cochin/Bangalore, India
Posts: 439
Try this:

Code:
var=$(sqlplus  -s USER/PASS@DB <<EOF | tail -1
set feedback off;
select name from v\$database;
EOF
)
Reply With Quote
  #3  
Old 09-01-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,930
Or:

Code:
dbname=$(sqlplus -s '/ as sysdba'<<\!
set pages 0 feed off
select name from v$database;
!
)
With recent bash (>=3 IIRC):

Code:
printf -vdbname 'set pages 0 feed off\nselect name from v$database;' | 
  sqlplus -s '/ as sysdba'

Last edited by radoulov; 09-01-2008 at 11:32 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 01:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0