Oracle SQL 脚本假脱机 &1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5421831/
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-18 23:09:00  来源:igfitidea点击:

Oracle SQL script spool &1

sqloracle

提问by Hyman

If i have 3 sql scripts and if i dump output in spool &1 in first sql script do i have to dump second sql script output in spool &2.. i am trying to getting all those output in another cshell script.. can some one explain me how does spool &1 works

如果我有 3 个 sql 脚本,并且如果我在第一个 sql 脚本中的 spool &1 中转储输出,我是否必须在 spool &2 中转储第二个 sql 脚本输出..我试图在另一个 cshell 脚本中获取所有这些输出..有人可以解释一下我如何 spool &1 工作

回答by Rob van Laarhoven

Asuming you have Version 10g or higher you have the following options:

假设您有 10g 或更高版本,您有以下选项:

SQL> spool name_of_file
SQL> spool name_of_file off
SQL> spool name_of_file out
SQL> spool name_of_file create
SQL> spool name_of_file append
SQL> spool name_of_file replace

Do not underestimate the power of oracles fine online documentation:

不要低估 oracles 精美在线文档的威力:

CRE[ATE]
Creates a new file with the name specified. 
REP[LACE]
Replaces the contents of an existing file. If the file does not exist, REPLACE creates the 
file. This is the default behavior.
APP[END]
Adds the contents of the buffer to the end of the file you specify.
OFF
Stops spooling.
OUT
Stops spooling and sends the file to your computer's standard (default) printer. This 
option is not available on some operating systems.
Enter SPOOL with no clauses to list the current spooling status

回答by Alex Poole

The &1is a positional parameter. Using spool &1means the output will go to a filename which you pass in as the first argument on the command line

&1是一个位置参数。使用spool &1意味着输出将转到您在命令行上作为第一个参数传入的文件名

If your csh script calls three SQL scripts and they all contain spools, they should each refer to &1, the second one does not use &2. (As long as the file name is the first argument in each case). And the 'counter' is reset to 1 for each SQL*Plus session. So if you have SQL scripts called query1.sql, query2.sql and query3.sql, your csh script might look something like:

如果您的 csh 脚本调用了三个 SQL 脚本并且它们都包含假脱机,则它们应分别引用&1,第二个不使用&2. (只要文件名是每种情况下的第一个参数)。并且对于每个 SQL*Plus 会话,“计数器”重置为 1。因此,如果您有名为 query1.sql、query2.sql 和 query3.sql 的 SQL 脚本,您的 csh 脚本可能类似于:

#!/bin/csh
sqlplus -s / @query1 output_file_1
sqlplus -s / @query2 output_file_2
sqlplus -s / @query3 output_file_3

Each of the SQL scripts will contain spool &1, and the output will go to different files. You can then refer to the output files elsewhere in the same csh script of you want.

每个 SQL 脚本都将包含spool &1,并且输出将转到不同的文件。然后,您可以在所需的同一 csh 脚本中的其他位置引用输出文件。

As Robert mentions in the documentation he quotes, if you want all the output to go to the same file, you'd need to pass the same file name to all three sqlpluscommands and make the second and third spool commands have the APP[END]argument.

正如罗伯特在他引用的文档中提到的那样,如果您希望所有输出都转到同一个文件,您需要将相同的文件名传递给所有三个sqlplus命令,并使第二个和第三个假脱机命令具有APP[END]参数。