2011-03-24 43 views
0

如果我有3个SQL脚本,并且如果我在第一个sql脚本中输出假脱机& 1,我必须在假脱机程序中输出第二个sql脚本输出& 2 ..我试图获取所有那些输出在另一cshell脚本..可有人给我解释一下如何做滑& 1作品Oracle SQL脚本假脱机&1

回答

1

&1是位置参数。使用spool &1装置的输出会去,你在通过在命令行上的第一个参数的文件名

如果您的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 

每个SQL脚本将包含spool &1,输出会去到不同的文件。然后你可以在你想要的同一个csh脚本的其他地方引用输出文件。

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

+0

谢谢..它帮助了很多 – jack 2011-03-24 16:40:06

1

Asuming你有版本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 

不要小看预言罚款在线的力量文档:

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