Detect sqlplus error in dos batch script?

送分小仙女□ 提交于 2019-11-30 17:53:44

问题


We have the following batch script:

(
echo @release.sql
echo exit
) | sqlplus x/y@orcl

if %errorlevel% gtr 1 goto dberror

Issue is - the statement if %errorlevel% gtr 1 never appears to be true when there is a sql error.

If we put garbage commands in the release.sql file, sqlplus does complain:

SQL> SP2-0042: unknown command "blah" - rest of line ignored.
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

But %errorlevel% still equals 0. How can we determine that there was a sql error?


Update: This code DOES appear to work for some sql errors. It will work if I do drop table blah but it won't work with just the command blah


回答1:


Take a look at:

WHENEVER SQLERROR

http://download.oracle.com/docs/cd/E11882_01/server.112/e16604/ch_twelve052.htm

WHENEVER OSERROR

http://download.oracle.com/docs/cd/E11882_01/server.112/e16604/ch_twelve051.htm



来源:https://stackoverflow.com/questions/4937108/detect-sqlplus-error-in-dos-batch-script

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