分类: Oracle
2009-01-05 22:46:07
利用SPOOL功能将查询得到的结果写入文件,并且屏蔽了所有不必要的输出。很简单的小东西,但是经常会用到。
Call.sql和execute.sql放到同一个目录中,execute.sql中存放需要执行的查询语句,而call.sql设置sqlplus的输出格式。
转自:http://yangtingkun.itpub.net/index.php
SQL> !more call.sql
Prompt ***********************************
Prompt sql_file = &1
Prompt spool_file = &2
Prompt "Exit:Ctrl+c; Continue:Enter."
ACCEPT choice CHAR PROMPT 'Please confirm your input:'
set feedback off
set pages 0
set lines 30000
set trims on
set trim on
set ver off
set hea off
set time off
set timing off
set autot off
set echo off
set show off
set term off
spo &2
@@&1
spo off
set feedback 6
set pages 14
set lines 80
set trims off
set ver on
set hea on
set term on
Prompt Spool to &2 successful!
Prompt ***********************************
SQL> !more exec.sql
SELECT * FROM tab where rownum <11 sql> @call exec.sql output.lst
***********************************
sql_file = exec.sql
spool_file = output.lst
"Exit:Ctrl+c; Continue:Enter."
Please confirm your input:^C
SQL> @call exec.sql output.lst
***********************************
sql_file = exec.sql
spool_file = output.lst
"Exit:Ctrl+c; Continue:Enter."
Please confirm your input:
Spool to output.lst successful!
***********************************
SQL> !more output.lst
ACCESSLOG TABLE
ACCESSLOG_BAK TABLE
ACCOUNT TABLE
ACCOUNTBALANCE TABLE
ACCOUNTCHANGE TABLE
ACCOUNTCHANGEOLD TABLE
ACCOUNTCHANGE_08TO11 TABLE
ACCOUNTINGCAVLOG TABLE
ACCOUNTINGCONFIRM TABLE
ACCOUNTINGCONFIRMHIS TABLE
SQL>