oracle 在dos批处理脚本中检测sqlplus错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4937108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect sqlplus error in dos batch script?
提问by Marcus Leon
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 %errorlevel% gtr 1
当出现 sql 错误时,该语句似乎永远不会为真。
If we put garbage commands in the release.sql file, sqlplus does complain:
如果我们将垃圾命令放在 release.sql 文件中,sqlplus 确实会抱怨:
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?
但是%errorlevel%
还是等于0,怎么判断是sql错误呢?
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
更新:此代码似乎适用于某些 sql 错误。如果我这样做drop table blah
它会起作用,但它不能仅使用命令blah
回答by RMAN Express
Take a look at:
看一眼:
WHENEVER SQLERROR
每当 SQLERROR
http://download.oracle.com/docs/cd/E11882_01/server.112/e16604/ch_twelve052.htm
http://download.oracle.com/docs/cd/E11882_01/server.112/e16604/ch_twelve052.htm
WHENEVER OSERROR
每当 OSERROR
http://download.oracle.com/docs/cd/E11882_01/server.112/e16604/ch_twelve051.htm
http://download.oracle.com/docs/cd/E11882_01/server.112/e16604/ch_twelve051.htm