Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Sqlplus and Unix : getting a non zero return code

Re: Sqlplus and Unix : getting a non zero return code

From: Pete's <empete2000_at_yahoo.com>
Date: 21 Aug 2001 05:31:25 -0700
Message-ID: <6724a51f.0108210431.30460f7a@posting.google.com>


Remove the check_error function, it will never make it there anyway in the event of a failure due to the way the code is written. Second, change your sqlplus 'exit' to 'exit success commit' even if it's just a select statement, it will return a zero return code then. It will then only return a non-zero return code if there is some type of oracle error since you have 'whenever sqlerror exit failure'

HTH
Pete's

stemp1ar_at_yahoo.com (Simon) wrote in message news:<8fe904ce.0108202023.7f6441fb_at_posting.google.com>...
> I need to call in the experts. I would like to call sqlplus, pass sql
> as a parm, run the sql and if there is a non zero return code exit the
> script. The test script below does not seem to send the output to
> correct output files.
>
> Any help would be great...TIA
>
> check_error() {
> if [[ -a errfile ]]; then
> err_count=$(grep -c -e ^[^$] errfile)
> else
> err_count=0
> fi
> if (( err_count > 0 )); then
> echo "\nErrors have been encountered. Please refer to
> errfile"
> fi
> }
> sqlplus -s > test.out 1>errfile 2>logfile <<EOF
> username/pass
> whenever sqlerror exit failure
> set serveroutput on
> spool outfile
> select count(*) from table_name;
> spool off;
> exit;
> EOF
>
> RC=$?
> if [[ $RC = 0 ]]; then
> echo "Inside zero rc=$RC"
> else
> echo "Inside non-zero RC=$RC"
> exit -1
> fi
>
> check_error
Received on Tue Aug 21 2001 - 07:31:25 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US