SQL*Plus : Force it to return an error code

梦想与她 提交于 2019-12-11 00:09:35

问题


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.


回答1:


WHENEVER SQLERROR EXIT 1




回答2:


If you care which application error your PL/SQL raised, you can declare the return code as a SQL*Plus variable, and return have the PL/SQL procedure set it.

#shell script

sqlplus /nolog << EOF
connect uid/pw
variable retval number;
BEGIN
  foo (:retval);
END;
/

exit retval;
EOF

return $?


来源:https://stackoverflow.com/questions/2254761/sqlplus-force-it-to-return-an-error-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!