批处理文件中的单个命令在某些情况下无法使用 sqlplus
Single command from batch file with sqlplus not working in some cases
我在批处理文件中有以下命令。
set tableName=%1
select count(1) from %tableName% where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^>(select to_char(max(DATEVALUE),'yyyy-mm-dd hh24:mi:ss') from FOO_TABLE); | sqlplus !connectionString!
这个说法不成立。我可以看到它连接到数据库然后断开连接。但以下作品:
select count(1) from %tableName% where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')=(select to_char(max(DATEVALUE),'yyyy-mm-dd hh24:mi:ss') from FOO_TABLE); | sqlplus !connectionString!
我猜问题可能出在 greater than >
符号上。我尝试了 ^>
、>
和 \>
。 None 其中有效。我怎样才能使这个 sql 语句起作用。
(我已经在前面几行的批处理文件中设置了 connectionString)。
命令行中的输出是
Connected to:
Oracle Database ... (more db info)
SQL> Disconnected from Oracle Database ... (more db info)
看来您还需要对 ^
转义字符进行转义;具体取决于您 运行 的处理方式,或者:
... where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^^>(select ...
或
... where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^^^>(select ...
在回显和管道查询的批处理文件中,三次转义有效:
@setlocal EnableDelayedExpansion
@set connectionString=x/y@z
@set tableName=bar
@echo select count(1) from %tableName% where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^^^>(select to_char(max(DATEVALUE),'yyyy-mm-dd hh24:mi:ss') from FOO_TABLE); | sqlplus !connectionString!
运行 该批处理脚本显示的语句是 运行(在我的例子中出现了预期的 ORA-00942 错误)。使用单个或双 ^
它与 SQL 提示符下的 运行 无关,而是创建一个文件,这似乎就是您所看到的。
我在批处理文件中有以下命令。
set tableName=%1
select count(1) from %tableName% where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^>(select to_char(max(DATEVALUE),'yyyy-mm-dd hh24:mi:ss') from FOO_TABLE); | sqlplus !connectionString!
这个说法不成立。我可以看到它连接到数据库然后断开连接。但以下作品:
select count(1) from %tableName% where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')=(select to_char(max(DATEVALUE),'yyyy-mm-dd hh24:mi:ss') from FOO_TABLE); | sqlplus !connectionString!
我猜问题可能出在 greater than >
符号上。我尝试了 ^>
、>
和 \>
。 None 其中有效。我怎样才能使这个 sql 语句起作用。
(我已经在前面几行的批处理文件中设置了 connectionString)。
命令行中的输出是
Connected to:
Oracle Database ... (more db info)
SQL> Disconnected from Oracle Database ... (more db info)
看来您还需要对 ^
转义字符进行转义;具体取决于您 运行 的处理方式,或者:
... where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^^>(select ...
或
... where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^^^>(select ...
在回显和管道查询的批处理文件中,三次转义有效:
@setlocal EnableDelayedExpansion
@set connectionString=x/y@z
@set tableName=bar
@echo select count(1) from %tableName% where to_char(DATEVALUE,'yyyy-mm-dd hh24:mi:ss')^^^>(select to_char(max(DATEVALUE),'yyyy-mm-dd hh24:mi:ss') from FOO_TABLE); | sqlplus !connectionString!
运行 该批处理脚本显示的语句是 运行(在我的例子中出现了预期的 ORA-00942 错误)。使用单个或双 ^
它与 SQL 提示符下的 运行 无关,而是创建一个文件,这似乎就是您所看到的。