標籤:問題 oracle解答
SPOOL可以把Oracle用戶端SQLPLUS的輸出匯入到一個文本中,可以匯出html、CSV等形式,其文法如下:
spool <filename> [rep/append]
螢幕輸出保留到指定檔案中,如果檔案存在想替換內容使用replace,追加內容到檔案中使用append
關閉並把輸出發送到系統印表機列印用spool out,不過這個命令在某些系統不能用
關閉螢幕內容輸出到檔案使用spool off
比如我們想要把Oracle各資料表空間的使用方式輸出為HTML格式的報表:
SET MARKUP HTML ON SPOOL ON pre off entmap off
SET ECHO OFF
SET TERMOUT OFF
SET TRIMOUT OFF
set feedback off
set heading on
set linesize 200
set pagesize 10000
col tablespace_name format a15
col total_space format a10
col free_space format a10
col used_space format a10
col used_rate format 99.99
spool /home/oracle/test.html
select a.tablespace_name,a.total_space_Mb||‘m‘ total_space,b.free_space_Mb||‘m‘
free_space,a.total_space_Mb-b.free_space_Mb||‘m‘ used_space,
(1-(b.free_space_Mb/a.total_space_Mb))*100 used_rate,a.total_blocks,b.free_blocks from
(select tablespace_name,sum(bytes)/1024/1024 total_space_Mb,sum(blocks) total_blocks from dba_data_files
group by tablespace_name) a,
(select tablespace_name, sum((bytes)/1024/1024) free_space_Mb,sum(blocks) free_blocks from dba_free_space
group by tablespace_name) b
where a.tablespace_name=b.tablespace_name order by used_rate desc;
spool off
最終匯出結果如下:
650) this.width=650;" src="http://note.youdao.com/yws/api/group/11158000/noteresource/AC5C6CE07F194559AD3D8F9CDE0C9AD0/version/22?method=get-resource&shareToken=7D22C6177FCC47A1B64333ACEB68D733&entryId=93917190" style="height:auto;border:0px;" alt="22?method=get-resource&shareToken=7D22C6" />
更多精彩oracle學習資源,盡在我贏職場!
http://www.wyzc.com/mysql/?tg=LXUK--Zkf&tg=3006123630
Oracle錄屏命令spool的使用