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!

Need to capture Connect error 1

Status
Not open for further replies.

prismtx

IS-IT--Management
Apr 9, 2001
59
0
0
US
I have a script which calls SQLPLUS and passes the login information. It is working great, but if the database is down or if it passes a bad parameter, the connect does not work, but I still get a return code of zero. Is there a way to capture when there is a connect error and exit with a return code?

This is what i have now:
Code:
set WHENEVER SQLERROR exit 1
set WHENEVER OSERROR exit 1
set serveroutput on size 100000
sqlplus /nolog <<EOF
connect $USERNAME/$PASSWORD@$1
select * from table1;
exit
EOF
if [ $? != 0 ]
then
  echo "NOT CONNECTED TO SQL"
  exit 1
fi
echo "Return Code = $?"

But I get these messages:
Code:
SQL> ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
SQL> SQL> Return Code = 0
 
It seems you are mixing Unix shell and PL/SQL syntax.

Put your three lines 'set ...' between 'sqlplus ...' and 'connect ...',
and replace 'set WHENEVER' by 'WHENEVER'

hope this helps
 
Thanks hoinz, moving those lines after sqlplus worked (and removing the set on the WHENEVER's)

It is a sqlplus call embedded in a unix script and now I am capturing the error as I had hoped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top