Oracle 10G中spool新增加的方法

charsi發表於2010-11-23

使用Oracle的時候,我們經常使用spool這個工具,來看看10G和9i中,SPOOL的用法:

10G中
SQL> help spool

SPOOL
-----

Stores query results in a file, or optionally sends the file to a printer.
In iSQL*Plus, use the Preferences screen to direct output to a file.

SPO[OL] [file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]] | OFF | OUT]

Not available in iSQL*Plus


SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production


9i中:
SQL> help spool

SPOOL
-----

Stores query results in an operating system file, or sends the
file to a printer.
In iSQL*Plus, output can be directed to a file.

SPO[OL] [file_name[.ext] | OFF | OUT]

Not available in iSQL*Plus


SQL> spool out
not spooling currently
SQL>
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for HPUX: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production


可以看出,在9i中spool的用法比較簡單,就是on和off的兩種功能;而到了10G中之後,可以在spool的檔名之後使用create(建立)、replace(替換)、append(新增)三個引數,尤其是append這個引數的引入.不用再像在9i中的時候,如果再次spool的時候,就會把原來的檔案替換掉.


SQL> spool test_spool cre
SQL> !ls -l
total 0
-rw-r--r-- 1 oracle dba 0 Feb 9 14:38 test_spool.lst

SQL> spool off


SQL> spool test_spool append
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production


SQL> spool off

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23850820/viewspace-1045875/,如需轉載,請註明出處,否則將追究法律責任。

相關文章