top
Loading...
用SQL*PLUS構建完美excel或html輸出

通過SQL*PLUS我們可以構建友好的輸出,滿足多樣化用戶需求。本例通過簡單示例,介紹通過sql*plus輸出xls,html兩種格式文件。

首先創建兩個腳本:

1.main.sql

用以設置環境,調用具體功能腳本。

2.功能腳本-get_tables.sql

為實現具體功能之腳本。

通過這樣兩個腳本可以避免spool中的冗余信息。

示例如下:

1.main.sql腳本:

[oracle@jumper utl_file]$ more main.sqlset linesize 200 set term off verify off feedback off pagesize 999 set markup html on entmap ON spool on preformat offspool tables.xls@get_tables.sqlspool offexit

2.get_tables.sql腳本:

[oracle@jumper utl_file]$ more get_tables.sql select owner,table_name,tablespace_name,blocks,last_analyzedfrom all_tables order by 1,2;

3.執行并獲得輸出:

[oracle@jumper utl_file]$ sqlplus "/ as sysdba" @mainSQL*Plus: Release 9.2.0.4.0 - Production on Mon Apr 25 10:30:11 2005Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.Connected to:Oracle9i Enterprise Edition Release 9.2.0.4.0 - ProductionWith the Partitioning optionJServer Release 9.2.0.4.0 - ProductionDisconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - ProductionWith the Partitioning optionJServer 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格式輸出,效果如下圖:

(T115)

作者:http://www.zhujiangroad.com
來源:http://www.zhujiangroad.com
北斗有巢氏 有巢氏北斗