我正在尝试使用 sql*plus 来控制一个小的 Windows 命令脚本。
基本上,我想执行一些 PL/SQL(可能从视图或表中选择或执行函数),它显示数据库中某些行的状态,然后根据行的状态执行一些 Windows 命令。
我的问题是如何将结果返回到命令脚本中。
sqlplus user/password@server @script.sql
IF <CONDITIONAL HERE BASED on script.sql results> GOTO :runprocess
REM log and email that process had to be skipped
EXIT
:runprocess
REM run various Windows service commands
我可能会从被调用的脚本(或条件,取决于要求)编写脚本script.sql
itself.
例如,以下script.sql
创建一个.bat 文件 windows_commands.bat
:
set feedback off
set echo off
set trimspool on
set termout off
set serveroutput on size 100000 format wrapped
set lines 500
set pages 0
-- create the bat file to be executed later:
spool windows_commands.bat
declare
c number;
begin
select count(*) into c from dual;
-- depending on a conditional, write the stuff to be executed into the
-- bat file (windows_commands.bat)
if c = 1 then
dbms_output.put_line('@echo everthing ok with dual');
else
dbms_output.put_line('@echo something terribly wrong with dual');
end if;
end;
/
spool off
exit
然后你可以打电话script.sql
来自另一个.bat 文件像这样:
@rem create oracle session, call script.sql
sqlplus %user%/%password%@%db% @script.sql
@rem script.sql has created windows_commands.bat.
@rem call this newly created bat file:
call windows_commands.bat
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)