Operating System - HP-UX
1752751 Members
5019 Online
108789 Solutions
New Discussion юеВ

Getting Exact Oracle errors returned by SQL from Shell script

 
KVS Raju
Advisor

Getting Exact Oracle errors returned by SQL from Shell script

Dear friends.
Iam calling some SQL scripts from Shell sript (HP UNIX) in the following way.

SCRIPTERROR1=0
SQLRESULTS1=`sqlplus -s user/$pass
@$SCRIPTNAME < $tmp/tmp.err`

echo $SQLRESULTS1 | grep -Eq 'ORA-|SP2-'
GREPOUTPUT2=$?
if [ $GREPOUTPUT1 -eq 0 ]
then
echo "********************************"
echo "ERROR 4 :"
echo "Error While droping:" echo "*******************************"
exit 99
fi

The echo output of "$SQLRESULTS1" contains
some other junk data along with oracle errors. We observed that the echo output displaying all file names in that directory along with Oracle errors.

Can please suggest me how to get only oracle errors in the echo output.

Thanks in advance
Time and Tide wait for none
3 REPLIES 3
Jean-Luc Oudart
Honored Contributor

Re: Getting Exact Oracle errors returned by SQL from Shell script

Hi,

not sure I read the script properly and/or if I understand fully yuor pb.

Anyway :
1) I would check a return code for the sqlplus run
e.g.
SQLRESULTS1=$(sqlplus -s user/$pass
@$SCRIPTNAME > $tmp/tmp.err)

RET=$?

2) in your SQL I would start probably with :
whenever sqlerror exit 99 ;
(hence test of return code in (1))

3) I would redirect output to the temp file (did I read it ok ?)

then :
if [[ $RET -ne 0 ]]; then
grep -e 'ORA-|SP2-' $tmp/tmp.err
fi

you will get the errors


Regards,
Jean-Luc
fiat lux
Muthukumar_5
Honored Contributor

Re: Getting Exact Oracle errors returned by SQL from Shell script

Are you getting input from $tmp/tmp.err file for sql operation or redirecting it???

If you want to put the contents on to $tmp/tmp.err file then, use as,
SQLRESULTS1=`sqlplus -s user/$pass
@$SCRIPTNAME > $tmp/tmp.err`

Else to append with old contents then,
SQLRESULTS1=`sqlplus -s user/$pass
@$SCRIPTNAME >> $tmp/tmp.err`

echo $SQLRESULTS1 | grep -Eq 'ORA-|SP2-'
GREPOUTPUT2=$?
if [ $GREPOUTPUT1 -eq 0 ]

--> we can simplify as,
echo $SQLRESULTS1 | grep -Eq 'ORA-|SP2-'
if [[ $? -eq 0 ]]
then

And more you can start to debug *Everything* or this part with set -x ?

set -x
SCRIPTERROR1=0
SQLRESULTS1=`sqlplus -s user/$pass
@$SCRIPTNAME > $tmp/tmp.err`

echo $SQLRESULTS1 | egrep -q 'ORA-|SP2-'
if [ $? -eq 0 ]
then
echo "********************************"
echo "ERROR 4 :"
echo "Error While droping:"
echo "*******************************"
exit 99
fi
set +x

Easy to suggest when don't know about the problem!
KVS Raju
Advisor

Re: Getting Exact Oracle errors returned by SQL from Shell script

Hi Friends

Thanks for your suggestions we found that the reason for junk is for " * " in SQL output.

so we have implemented as below

SCRIPTERROR1=0
sqlplus -s ystem/$spass @$SCRIPTNAME<$tmp/tmp.err > /tmp/com_outpu.txt
SCRIPTERROR1=$?
echo " "
echo " checking data "
echo " "
grep -Eq 'ORA-|SP2-' /tmp/com_outpu.txt > /dev/null

if [ $? -eq 0 ]; then
echo " ************************************"
echo " ERROR 4"
echo "Error While droping "
cat /tmp/com_outpu.txt
echo "*********************************"
exit 1
fi
Time and Tide wait for none