DOS BAT命令:验证SQL PLUS SQL查询

时间:2012-03-28 08:32:41

标签: batch-file sqlplus

我在.bat文件中创建了以下命令:

@echo select count(*) from table where column1 = 'abc'; | sqlplus username/password@database

根据返回的结果,我需要不同的SQL。我该怎么办?

e.g。如果返回的结果集是0,我需要它退出.bat文件。如果结果集不是0(1或> 1),那么我将执行另一个SQL语句。

请帮忙。

1 个答案:

答案 0 :(得分:0)

这取决于如何提供输出,但以下内容应该有效:

@echo off
set tempfile=%temp%\%random%.log
echo select count(*) from table where column1 = 'abc'; | sqlplus username/password@database > "%tempfile%"
findstr /c:"INVALID" "%tempfile%" >nul 2>&1 && echo No resultset || echo some other statement | sqlplus username/password@database
相关问题