sql - 数据库查询在批处理文件中不起作用
问题描述
@echo off
set user_name=username
set password=
set sid=sid
@echo select distinct scid, to_char(dlog_on_timestamp,'dd-Mon-YYYY hh:mi:ss') from table where dlog_on_timestamp > sysdate-7; | sqlplus -s %user_name%/%password%@%sid% >> C:\Users\test.txt
在运行这个批处理文件时, > 符号创建了文件 sysdate-7. 但我需要运行数据库查询,结果应该存储在 test.txt
解决方案
cmd.exe
在命令周围为您的 shell (?) 加上引号:
@echo "select distinct scid, to_char(dlog_on_timestamp,'dd-Mon-YYYY hh:mi:ss') from table where dlog_on_timestamp > sysdate-7;" | sqlplus -s %user_name%/%password%@%sid% >> C:\Users\test.txt