oracle 在单个 unix shell 脚本中执行多个 SQL 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16797186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:41:34  来源:igfitidea点击:

To execute multiple SQL files in single unix shell script

oracleunix

提问by Chandru

I have a SQL filequery.sqlrunning thorugh a unix shell script and it directs an ouput to another SQL file called as result.sql

我有一个query.sql通过 unix shell 脚本运行的 SQL 文件,它将输出定向到另一个名为的 SQL 文件result.sql

First file will give the sample output of below which will be written in the result.sql,

第一个文件将给出下面的示例输出,将写入 result.sql,

drop * from table1;
drop * from table 2;
drop * from table 3;  etc.. 

I need to execute both query.sqland result.sqlin a single shell script and this should create a output file called as output.txt. How can I achieve this?

我需要在单个 shell 脚本中同时执行query.sqlresult.sql,这应该创建一个名为output.txt. 我怎样才能做到这一点?

回答by Ed Gibbs

Something on this idea should work:

关于这个想法的一些东西应该有效:

sqlplus -s username/password@servername << EOF
@query.sql
spool output.txt
@result.sql
spool off
EOF