简体   繁体   English

使用SQLPLUS中的数据库值作为批处理文件的参数

[英]Use a database value in SQLPLUS as a parameter to a batch file

I need to run a batch file and pass in a database value. 我需要运行批处理文件并传入数据库值。 Depending on the day, a different value needs to be passed into the DOS command. 根据日期,需要将不同的值传递到DOS命令。 This particular business rule is defined in a view in the database. 此特定业务规则在数据库的视图中定义。

Our primary scheduling tool is datastage which runs scripts in SQLPLUS, so this is my preferred method for schedules activities. 我们的主要调度工具是在SQLPLUS中运行脚本的数据存储,因此这是我首选的调度活动方法。 I could also run a batch file directly taht calls SQLPLUS and gets a value, but there is much more hassle setting it up so I'd prefer not to. 我也可以直接运行一个批处理文件,直接调用SQLPLUS并获取一个值,但是设置它会有更多的麻烦,所以我不想这样做。

I'm a SQLPLUS amateur. 我是一个SQLPLUS业余爱好者。

The SQL script I'm passing into SQLPLUS is below. 我传入SQLPLUS的SQL脚本如下。 The problem I'm having is it's passing in :sTriggerName, not the value of it. 我遇到的问题是传入:sTriggerName,而不是它的值。

set echo on
set feedback on
set termout on


VAR sTriggerName VARCHAR2(100)

SELECT TRIGGERNAME INTO :sTriggerName 
FROM SCHEMA.VIEW 
WHERE CALENDAR_DATE = TRUNC(SYSDATE) AND ROWNUM < 2;
/

HOST "E:\CallScheduleTrigger.CMD :sTriggerName."

quit

In the example above I am using a bind variable. 在上面的例子中,我使用的是绑定变量。

This link showed me hwo to load a substitution variable from the database and use that instead: 这个链接显示我要从数据库加载一个替换变量并使用它代替:

http://www.oracle.com/technetwork/testcontent/sub-var9-086145.html http://www.oracle.com/technetwork/testcontent/sub-var9-086145.html

To load aa database value into a substitution variable called sTriggerName 将数据库值加载到名为sTriggerName的替换变量中

COLUMN TRIGGERNAME new_value sTriggerName
SELECT TRIGGERNAME FROM SCHEMA.VIEW WHERE CALENDAR_DATE = TRUNC(SYSDATE) AND ROWNUM < 2;

To use this substitution variable in a host command (ie as a parameter to a batch file): 要在主机命令中使用此替换变量(即作为批处理文件的参数):

HOST "E:\CallScheduleTrigger.CMD &sTriggerName"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM