Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Returning SQL.SQLCODE from SQLPLUS
Hi!
I believe you're getting weird numbers from SQL*Plus termination codes (when using EXIT SQL.SQLCODE) because all Unix shells (including MKS's KSH under NT) map the exit code to a number between 0 and 255.
If the program's exit code is greater than 255, what you get from $? is actually the exit code modulo 256 (exitCode % 256). This is a shell's fundamental limitation...
EXIT SQL.SQLCODE does convert SQLCODE to a positive integer but when this value is passed to the shell it is truncated to a 256 radix. Alas, any ORA- error greater than 255 will be lost.
As you stated, any attempt to check SQLCODE from a subsequent PL/SQL block will implicitly reset it to 0.
If you can map anticipated Oracle error codes to application-defined codes between 0 and 255 there is a way to force SQL*Plus to exit with the proper number. This is (somewhat kludgily) illustrated as follows:
/******************************************************************************/
Note that by not re-raising the error, the PL/SQL procedure will appear to complete satisfactorily...*/
/*
This code implicitly DEFINEs a SQL*Plus "exitCode" variable
from the value stored in ":applCode"
*/
COLUMN exitCode NOPRINT NEW_VALUE exitCode
SELECT :applCode AS exitCode
FROM dual;
Hope this helps...
Regards,
Ricardo Rocha
Plenix Inc
Received on Sun Sep 13 1998 - 11:43:50 CDT