首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> SQL Server 資料庫 >> 關於SqlServer

SQL*Plus 產出完美 Excel/HTML 報表輸出技巧

     編輯:關於SqlServer

雙腳本架構避免 Spool 雜訊

  • main.sql:設定環境、呼叫功能腳本
  • get_tables.sql:實際查詢邏輯

腳本內容

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

get_tables.sql

select owner, table_name, tablespace_name, blocks, last_analyzed
from all_tables order by 1,2;

執行與輸出

sqlplus "/ as sysdba" @main
ls -l tables.xls
# -rw-r--r-- 1 oracle dba 69539 Apr 25 10:30 tables.xls

輸出格式切換

將 spool tables.xls 改為 spool tables.htm 即可產出 HTML 格式。兩種格式輸出效果圖如下:

Excel 輸出效果

HTML 輸出效果

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved