我有一个脚本getCount.sql,用于从表中提取记录数。查询如下。
connect user/pwd@DB
spool C:\filepath\filename.txt
select count(distinct(column name))
from table name
where condition
/
spool off
exit;
我使用命令
从getCount.bat文件中调用它sqlplus /nolog @C:\filepath\getCount.sql
我能够将输出输入文件filename.txt。我需要帮助将它存储到getCount.bat批处理文件中的变量中,并将其用于进一步计算。
答案 0 :(得分:0)
声明一个Number类型的变量,选择count到该变量:
connect user/pwd@DB
spool C:\filepath\filename.txt
Declare MyNumber Number;
BEGIN
select count(distinct(Column_Name))
into MyNumber
from table_name
where condition;
IF MyNumber > 0 THEN
-- Do Stuff Here ....
END IF;
END;
/
spool off
exit;
答案 1 :(得分:0)
您可以使用SQL创建新的.bat文件,然后运行它。
答案 2 :(得分:0)
只需更改文件的文件扩展名即可。结果将保存在.bat文件中
连接user / pwd @ DB spool C:\ filepath \ filename.bat
选择计数(不同(列名)) 从表名 条件 /
假脱机 出口;