Re: Pass Return Code to Shell
Date: 1996/04/03
Message-ID: <4ju5ga$5c6_at_doc.zippo.com>#1/1
In article <4jrokg$2jl_at_news.dca.net>, jennings_at_dca.net says...
>
>I'm running SQL scripts within a Kourne Shell script. If the
>SQL encounters an error, I want the return code to be propagated
>out to the shell return code ($?). Does anyone know how to do this??
>
>Ed
Here's how I do it (this code verifies user input before sending it to a batch scheduler):
temp=`sqlplus -s / <<-!! set head off feedback off termout off echo off whenever sqlerror exit sql.code; select to_date('$arg1','$date_format') from dual; exit;` if [ $? = 0 ] then break; else echo "The date [$arg1] was invalid or not in [$date_format] format." fi
The normal return code is 0. If the SQL causes an error, it will pass that
error back to the shell using the SQL error code. This was set by the line
'whenever sqlerror exit sql.code'.
This code fragment is run directly from the shell.
What is not shown is that it prompts the user for a date ($arg1) using
a default date format ($date_format). The date format is set by the
shell using a statement like:
date_format=MM/DD/YYYY Received on Wed Apr 03 1996 - 00:00:00 CEST