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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:41:20  来源:igfitidea点击:

Detect sqlplus error in dos batch script?

oraclesqlplusbatch-file

提问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 1never 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 blahbut it won't work with just the command blah

更新:此代码似乎适用于某些 sql 错误。如果我这样做drop table blah它会起作用,但它不能仅使用命令blah