【发布时间】:2017-09-01 00:51:01
【问题描述】:
我一直在我的批处理脚本中使用以下命令从远程数据库中获取结果。
for /f %%m in ('sqlplus -S debayan/[pwd]@[ip]:[port]/[DBInstance] @selectcommands.sql') do set theValue=%%m
echo on
echo "%theValue%"
PAUSE
echo off
在打印时,值为
echo "" 没有变量 theValue 的值,它应该返回选择查询的值。
我的sql文件有如下简单语句
set termout off
set echo off
set pagesize 0
set linesize 500
set heading off
set verify off
set feedback off
set heading off
set serveroutput on
whenever sqlerror exit 16
whenever oserror exit 8
set autocommit on
SET ROWCOUNT 1
set heading off
select count(*) from books;
commit;
exit;
非常感谢任何帮助。
【问题讨论】:
-
尝试
for /f "TOKENS=*" %%m in ('…') do ECHO set "theValue=%%m"以查看在for循环中处理的所有…命令输出。 (使用您的命令代替…水平省略号。) -
您好,这会产生与前一种情况相同的响应。但是,我能够通过使用
do @ set并通过删除.sql文件中我的sql 查询之前的所有语句来生成变量的结果。这给了我需要的答案。但是,作为一种编程实践,不确定这是好事还是坏事。
标签: windows oracle batch-file sqlplus