最近工做中,需對數據進行比對。在此以前,則需將數據導出。想到之前用過的spool命令,實驗一番,分享以下:sql
需建SQL執行腳本,內容以下:oracle
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 offspa
執行該腳本,最後/home/oracle/test.txt顯示的內容即爲表dept的數據:code
50 IT CHINA
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 IT CHICAGO
40 OPERATIONS BOSTONblog
沒有開頭的SQL> select * from dept;和結尾的SQL> spool offip
結合官檔,總結一下SQL*Plus關於格式輸出的命令:it
SET ECHO {ON | OFF} Controls whether the START command lists each command in a script as the command is executed.io
SET FEED[BACK] {6 | n | ON | OFF} Displays the number of records returned by a query when a query selects at least n records.ast
SET HEA[DING] {ON | OFF} Controls printing of column headings in reports.class
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語句,從定義上看有點費解,下面咱們來看一下實驗結果:
1、 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
2、 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