spool命令


最近工作中,需對數據進行比對。在此之前,則需將數據導出。想到以前用過的spool命令,實驗一番,分享如下:

需建SQL執行腳本,內容如下:

set feedback off   --關掉行數顯示
set heading off     --關掉標題行
set termout off    --關掉終端顯示
set echo off         --關掉回顯
set pagesize 0     --去掉頭頂的空行
set trims on        --去掉空字符
spool /home/oracle/test.txt
select * from dept;
spool off

執行該腳本,最后/home/oracle/test.txt顯示的內容即為表dept的數據:

50 IT CHINA
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 IT CHICAGO
40 OPERATIONS BOSTON

沒有開頭的SQL> select * from dept;和結尾的SQL> spool off

結合官檔,總結一下SQL*Plus關於格式輸出的命令:

SET ECHO {ON | OFF}                       Controls whether the START command lists each command in a script as the command is executed.

SET FEED[BACK] {6 | n | ON | OFF}    Displays the number of records returned by a query when a query selects at least n records.

SET HEA[DING] {ON | OFF}                Controls printing of column headings in reports.

SET LIN[ESIZE] {80 | n}                    Sets the total number of characters that SQL*Plus displays on one line before beginning a new line.

SET LONG {80 | n}                            Sets maximum width (in bytes) for displaying LONG, BLOB, BFILE, CLOB, NCLOB and XMLType values; and for                                                      copying LONG values.

SET PAGES[IZE] {14 | n}                   Sets the number of lines in each page. 

SET TERM[OUT] {ON | OFF}               Controls the display of output generated by commands executed from a script.

SET TI[ME] {ON | OFF}                      Controls the display of the current time.

SET TIMI[NG] {ON | OFF}                   Controls the display of timing statistics.

SET TRIMS[POOL] {ON | OFF}             Determines whether SQL*Plus puts trailing blanks at the end of each spooled line.

SET TRIM[OUT] {ON | OFF}                Determines whether SQL*Plus puts trailing blanks at the end of each displayed line.

SET VER[IFY] {ON | OFF}                   Controls whether SQL*Plus lists the text of a SQL statement or PL/SQL command before and after SQL*Plus

                                                      replaces substitution variables with values.

SET WRA[P] {ON | OFF}                     Controls whether SQL*Plus truncates the display of a SELECTed row if it is too long for the current line width

PS:關於SET ECHO語句,從定義上看有點費解,下面我們來看一下實驗結果:

一、 SET ECHO OFF

      1> 編輯SQL腳本t1.sql如下:

          set echo off

          select * from dept;

       2> 執行該腳本       

SQL> @t1.sql

    DEPTNO DNAME      LOC
---------- -------------- -------------
    50 IT          CHINA
    10 ACCOUNTING      NEW YORK
    20 RESEARCH      DALLAS
    30 IT          CHICAGO
    40 OPERATIONS      BOSTON

二、 SET ECHO ON

      1> 編輯SQL腳本t1.sql如下:

          set echo on

          select * from dept;

      2> 執行該腳本

SQL> @t1.sql
SQL> select * from dept;

    DEPTNO DNAME      LOC
---------- -------------- -------------
    50 IT          CHINA
    10 ACCOUNTING      NEW YORK
    20 RESEARCH      DALLAS
    30 IT          CHICAGO
    40 OPERATIONS      BOSTON

 

      

  

 

           

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM