Oracle SQL脚本假脱机& 1

时间:2011-03-24 15:46:38

标签: sql oracle

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

2 个答案:

答案 0 :(得分:1)

假设你有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

不要低估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

答案 1 :(得分:1)

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

如果您的csh脚本调用三个SQL脚本且它们都包含假脱机,则它们应分别引用&1,第二个不使用&2。 (只要文件名是每种情况下的第一个参数)。每个SQL * Plus会话的'counter'都会重置为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

每个SQL脚本都包含spool &1,输出将转到不同的文件。然后,您可以在相同的csh脚本中的其他地方引用输出文件。

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