【问题标题】:Batch File SQL scripts in one single file单个文件中的批处理文件 SQL 脚本
【发布时间】:2019-05-02 18:35:52
【问题描述】:

我正在使用 运行 .sql 脚本:

@ECHO OFF
SET /p usr=username: 
SET /p pwd=password: 
SET /p dbname=dbname: 
set /p tablename=tablename:

sqlplus %usr%/%pwd%@%dbname%.sql

select * from table where (something);
select (something) from table where (something);
exit;

.bat 文件和.sql 脚本需要在一个文件中,所以我不能调用.sql 文件。 有任何想法吗? (如果有帮助,我正在使用 Windows 7).

【问题讨论】:

  • 自解压档案怎么样?

标签: batch-file sqlplus batch-file sqlplus


【解决方案1】:

只是一个想法,但为什么不从你的 bat 文件创建 sql 文件,将 sql 命令写入它,然后执行它。完成后,您可以删除 sql 文件。

@ECHO OFF
SET /p usr=username: 
SET /p pwd=password: 
SET /p dbname=dbname: 
set /p tablename=tablename:

SET "sql1=select * from table where ^(something^)^;"
SET "sql2=select ^(something^) from table where ^(something^)^;"
SET "sql3=^(SELECT 1 + LEVEL-1 idx FROM dual CONNECT BY LEVEL ^<^= 10^)^;"

@echo %sql1% > temp.sql
@echo %sql2% >> temp.sql
@echo %sql3% >> temp.sql

sqlplus %usr%/%pwd% @temp.sql

更新代码以允许需要转义的特殊字符,使用 ^ 转义特殊字符。

您可能还想查看this answer

希望一切顺利。

【讨论】:

  • 是的,但是如果我做这样的事情 echo (SELECT 1 + LEVEL-1 idx FROM dual CONNECT BY LEVEL temp.sql 它会说文件未指定。
  • 嗨,马克,我已经更新了答案以允许使用特殊字符。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-05
  • 2011-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多