检测sqlplus的错误在DOS批处理脚本? [英] Detect sqlplus error in dos batch script?
问题描述
我们有以下批处理脚本:
We have the following batch script:
(
echo @release.sql
echo exit
) | sqlplus x/y@orcl
if %errorlevel% gtr 1 goto dberror
问题是 - 声明如果%ERRORLEVEL%GTR 1
从不出现时,有一个SQL错误是真实的。
Issue is - the statement if %errorlevel% gtr 1
never appears to be true when there is a sql error.
如果我们把垃圾命令在release.sql文件,sqlplus中也抱怨:
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
但%ERRORLEVEL%
还是等于0,我们如何确定,有一个SQL错误?
But %errorlevel%
still equals 0. How can we determine that there was a sql error?
更新:这code确实出现了一些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
推荐答案
在看看:
WHENEVER SQLERROR
WHENEVER SQLERROR
<一个href=\"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
WHENEVER OSERROR
<一个href=\"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
这篇关于检测sqlplus的错误在DOS批处理脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!