【问题标题】:Oracle SQL script spool &1Oracle SQL 脚本假脱机 &1
【发布时间】:2011-03-24 15:46:37
【问题描述】:

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

【问题讨论】:

    标签: sql oracle


    【解决方案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 脚本中引用其他地方的输出文件。

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

    【讨论】:

      【解决方案2】:

      假设您拥有 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
      

      【讨论】:

        猜你喜欢
        • 2011-02-03
        • 2012-01-25
        • 1970-01-01
        • 1970-01-01
        • 2013-05-19
        • 1970-01-01
        • 2020-11-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多