使用SQL*PLUS,構建完美excel或html輸出
時間:2010-02-17 18:09來源: 作者: 點擊:次
摘自 http://www.eygle.com/archives/2005/04/eoasqlplusieaae.html Blueice2 發表于 2005年08月24日14時42分 通過SQL*PLUS我們可以構建友好的輸出,滿足多樣化用戶需求。 本例通過簡單示例,介紹通過sql*plus輸
摘自
http://www.eygle.com/archives/2005/04/eoasqlplusieaae.html
|
| Blueice2 發表于 2005年08月24日14時42分 |
通過SQL*PLUS我們可以構建友好的輸出,滿足多樣化用戶需求。 本例通過簡單示例,介紹通過sql*plus輸出xls,html兩種格式文件. 首先創建兩個腳本: 1.main.sql 用以設置環境,調用具體功能腳本 2.功能腳本-get_tables.sql 為實現具體功能之腳本 通過這樣兩個腳本可以避免spool中的冗余信息,參考: 如何去除SQLPLUS中SPOOL的冗余信息
示例如下: 1.main.sql腳本:
[oracle@jumper utl_file]$ more main.sql
set linesize 200
set term off verify off feedback off pagesize 999
set markup html on entmap ON spool on preformat off
spool tables.xls
@get_tables.sql
spool off
exit
|
2.get_tables.sql腳本:
[oracle@jumper utl_file]$ more get_tables.sql
select owner,table_name,tablespace_name,blocks,last_analyzed
from all_tables order by 1,2;
|
3.執行並獲得輸出:
[oracle@jumper utl_file]$ sqlplus "/ as sysdba" @main
SQL*Plus: Release 9.2.0.4.0 - Production on Mon Apr 25 10:30:11 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
[oracle@jumper utl_file]$ ls -l tables.xls
-rw-r--r-- 1 oracle dba 69539 Apr 25 10:30 tables.xls
[oracle@jumper utl_file]$
|
此處輸出為xls文件,通過下圖我們可以看到輸出效果:
把main.sql腳本中的,spool tables.xls更改為spool tables.htm,我們可以獲得htm格式輸出,效果如下圖:
 |
------分隔線----------------------------