Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oracle sqlplus row returned pass to variable 1

Status
Not open for further replies.

GROKING

Programmer
Mar 8, 2005
26
0
0
US

want to pass sqlplus row returned to a variable then evaluated.

#!/bin/bash
$ORAHOME/bin sqlplus "/ as sysdba" <<EOS
select count(*) from dual;
EOS

cvalue=$?

if [ $cvalue = 0 ] then
mail -s "zero rows were returned" groking@email.com
fi

 
Try this:

Code:
#!/bin/bash

cvalue=$(
$ORAHOME/bin sqlplus "/ as sysdba" <<EOS
set linesize 132
set pagesize 999
set head off
set feed off
select count(*) from dual;
EOS
)

if [ "$cvalue" = 0 ] then
 mail -s "zero rows were returned" groking@email.com
fi

The set bits are to remove column headings and so-on from the output, so you just get the row count. You may also want to check the value of $? in case sqlplus was unable to connect to the datbase at all.

Annihilannic.
 

that looks good. Ill give it a try. I asked two senior unix/oracle dba's and they suggested spool to file. nice!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top