程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 用SQL*PLUS構建完美excel或html輸出

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

編輯:關於SqlServer

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

首先創建兩個腳本:

1.main.sql

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

2.功能腳本-get_tables.sql

為實現具體功能之腳本。

通過這樣兩個腳本可以避免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格式輸出,效果如下圖:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved