Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL*Plus : Force it to return an error code

I have a stored procedure that has an OUT parameter, indicating an error code. If the error code is not 0, then I raise an error

DECLARE
BEGIN
 foo (err_code);

 IF (err_code <> 0) THEN
   raise_application_error(...);

END;

So far so good, but here's my question.

This piece of code (shown above) is executed by sqlplus, which is called from a shell script, which should exit with 0 / not 0 (as the sql script).

#shell script

sqlplus ... @myscript
return $?

When the raise_application_error executes, control goes back to sqlplus.

sql>

What I want, is a way of exiting back to the shell, without sqlplus returning a 0 on $?

Any thoughts? Thanks in advance.

like image 321
Tom Avatar asked Feb 02 '26 14:02

Tom


1 Answers

WHENEVER SQLERROR EXIT 1

like image 130
Gary Myers Avatar answered Feb 04 '26 07:02

Gary Myers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!