sql嵌入html格式顯示報表
比如我們要監控表空間的使用情況,輸出列有表空間名,狀態,區管理方式,總共的空間,使用的空間,剩餘的空間等。
如果顯示成下面的形式,儘管在輸出中嘗試使結果看起來清晰一些,但是還是事與願違。
Tablespace: TEST_INDEX |
Status: OLN |
Ext_MGR: LOCAL |
Total: 301843MB |
Free: 30937MB |
Used: 270906MB |
PFree: 10% |
Tablespace: TEST_DATA |
Status: OLN |
Ext_MGR: LOCAL |
Total: 7960MB |
Free: 422MB |
Used: 7537MB |
PFree: 5% |
Tablespace: TEST_INDEX |
Status: OLN |
Ext_MGR: LOCAL |
Total: 550MB |
Free: 55MB |
Used: 494MB |
PFree: 10% |
Tablespace: TEST_DATA2 |
Status: OLN |
Ext_MGR: LOCAL |
Total: 45167MB |
Free: 2302MB |
Used: 42865MB |
PFree: 5% |
Tablespace: TEST_INDEX2 |
Status: OLN |
Ext_MGR: LOCAL |
Total: 13990MB |
Free: 688MB |
Used: 13301MB |
PFree: 5% |
儘管sqlplus本身提供了 markup html on的選項,但是在orabbix中還是使用受限,所以只能另闢蹊徑。
檢查表空間的指令碼如下,只是一個參考例子。
select
d.tablespace_name,
decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status) status,
d.extent_management,
decode(d.allocation_type,
'USER','',
d.allocation_type) allocation_type,
(case
when initial_extent < 1048576
then lpad(round(initial_extent/1024,0),3)||'K'
else lpad(round(initial_extent/1024/1024,0),3)||'M'
end) Ext_Size,
NVL (a.bytes / 1024 / 1024, 0) MB,
NVL (f.bytes / 1024 / 1024, 0) free,
(NVL (a.bytes / 1024 / 1024, 0) - NVL (f.bytes / 1024 / 1024, 0)) used,
NVL (l.large / 1024 / 1024, 0) largest,
d.MAX_EXTENTS ,
lpad(round((f.bytes/a.bytes)*100,0),3) pfree,
(case when round(f.bytes/a.bytes*100,0) >= 20 then ' ' else '*' end) alrt
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) f,
(SELECT tablespace_name, MAX(bytes) large
FROM dba_free_space
GROUP BY tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND NOT (d.extent_management LIKE 'LOCAL' AND d.contents LIKE 'TEMPORARY')
UNION ALL
select
d.tablespace_name,
decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status) status,
d.extent_management,
decode(d.allocation_type,
'UNIFORM','U',
'SYSTEM','A',
'USER','',
d.allocation_type) allocation_type,
(case
when initial_extent < 1048576
then lpad(round(initial_extent/1024,0),3)||'K'
else lpad(round(initial_extent/1024/1024,0),3)||'M'
end) Ext_Size,
NVL (a.bytes / 1024 / 1024, 0) MB,
(NVL (a.bytes / 1024 / 1024, 0) - NVL (t.bytes / 1024 / 1024, 0)) free,
NVL (t.bytes / 1024 / 1024, 0) used,
NVL (l.large / 1024 / 1024, 0) largest,
d.MAX_EXTENTS ,
lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3) pfree,
(case when nvl(round(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,0),100) >= 20 then ' ' else '*' end) alrt
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_temp_files
GROUP BY tablespace_name order by tablespace_name) a,
(SELECT tablespace_name, SUM(bytes_used ) bytes
FROM v\$temp_extent_pool
GROUP BY tablespace_name) t,
(SELECT tablespace_name, MAX(bytes_cached) large
FROM v\$temp_extent_pool
GROUP BY tablespace_name order by tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND d.extent_management LIKE 'LOCAL'
AND d.contents LIKE 'TEMPORARY'
ORDER by 1
可以看到指令碼還是相對比較複雜的,這麼複雜的功能都能實現,但是展現的效果卻打了折扣,導致了功能上的豐富和顯示效果不太相符。
這個時候還是得考慮嵌入點html程式碼,自己也著實溫習了一下以前html的東西。
在經過了大量的測試之後,總算做出了一些改進。
最終需要sql查出來的結果需要時下面的格式:
<table border='1' width='90%' align='center' ><tr><td width="40%">Tablespace: TEST_TABLE
SPACE_DATA</td>
<td width="10%">Status: OLN</td> <td width="10%">Ext_MGR: LOCAL</td>
<td width="10%">Total: 29031.875MB</td>
<td width="10%">Free: 5.3125MB</td>
<td width="10%">Used: 29026.5625MB</td>
<td width="10%">PFree: 0%</td></tr></table>
<table border='1' width='90%' align='center' ><tr><td width="40%">Tablespace: TEST_TABLE2
SPACE_INDEX</td>
<td width="10%">Status: OLN</td> <td width="10%">Ext_MGR: LOCAL</td>
<td width="10%">Total: 12876.8125MB</td>
<td width="10%">Free: 10.6875MB</td>
<td width="10%">Used: 12866.125MB</td>
<td width="10%">PFree: 0%</td></tr></table>
實現的sql的程式碼如下,這個時候已經不是單純的指令碼了,我叫它程式碼了。:)
select
'<table border='||chr(34)||'1'||chr(34)||' width='||chr(34)||'90%'||chr(34)||' align='||chr(34)||'center'||chr(34)||'<tr>'||
'<td width='||chr(34)||'40%'||chr(34)||'>Tablespace: '||d.tablespace_name||'</td>',
'<td width='||chr(34)||'10%'||chr(34)||'>Status: '||decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status)||'</td>' status,
'<td width='||chr(34)||'10%'||chr(34)||'>Ext_MGR: '||d.extent_management||'</td>',
'<td width='||chr(34)||'10%'||chr(34)||'>Total: '||trunc(NVL (a.bytes / 1024 / 1024, 0))||'MB</td>' MB,
'<td width='||chr(34)||'10%'||chr(34)||'>Free: '||trunc(NVL (f.bytes / 1024 / 1024, 0))||'MB</td>' free,
'<td width='||chr(34)||'10%'||chr(34)||'>Used: '||trunc((NVL (a.bytes / 1024 / 1024, 0) - NVL (f.bytes / 1024 / 1024, 0)))||'MB</td>' used,
'<td width='||chr(34)||'10%'||chr(34)||'>PFree: '||lpad(round((f.bytes/a.bytes)*100,0),3)||'%</td></tr></table>' pfree
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) f,
(SELECT tablespace_name, MAX(bytes) large
FROM dba_free_space
GROUP BY tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND NOT (d.extent_management LIKE 'LOCAL' AND d.contents LIKE 'TEMPORARY')
AND lpad(round((f.bytes/a.bytes)*100,0),3)<=10
UNION ALL
select
'<table border='||chr(34)||'1'||chr(34)||' width='||chr(34)||'90%'||chr(34)||' align='||chr(34)||'center'||chr(34)||'<tr>'||
'<td width='||chr(34)||'40%'||chr(34)||'>Tablespace:'||d.tablespace_name||'</td>',
'<td>Status: '||decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status)||'</td>' status,
'<td width='||chr(34)||'10%'||chr(34)||'>Ext_MGR: '||d.extent_management||'</td>',
'<td width='||chr(34)||'10%'||chr(34)||'>Total: '||trunc(NVL (a.bytes / 1024 / 1024, 0))||'MB</td>' MB,
'<td width='||chr(34)||'10%'||chr(34)||'>Free: '||trunc((NVL (a.bytes / 1024 / 1024, 0) - NVL (t.bytes / 1024 / 1024, 0)))||'MB</td>' free,
'<td width='||chr(34)||'10%'||chr(34)||'>Used: '||trunc(NVL (t.bytes / 1024 / 1024, 0))||'MB</td>' used,
'<td width='||chr(34)||'10%'||chr(34)||'>PFree: '||lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3)||'%</td></tr></table>' pfree
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_temp_files
GROUP BY tablespace_name order by tablespace_name) a,
(SELECT tablespace_name, SUM(bytes_used ) bytes
FROM v$temp_extent_pool
GROUP BY tablespace_name) t,
(SELECT tablespace_name, MAX(bytes_cached) large
FROM v$temp_extent_pool
GROUP BY tablespace_name order by tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND d.extent_management LIKE 'LOCAL'
AND d.contents LIKE 'TEMPORARY'
AND lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3) <= 10
ORDER by 1;
可以在適當的時候來嘗試使用一下,效果雖然還是醜了些,不過已經做過格式化了。
改進的方向其實還是很多。比如嵌入顏色,格式佈局等等都是需要改進的方向。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23718752/viewspace-1777927/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP CRM WebClient UI html 格式的 Text 顯示邏輯WebclientUIHTML
- HTML特殊字元顯示HTML字元
- Layui表格日期格式顯示UI
- SAP CRM WebClient UI上以html格式顯示note的問題討論WebclientUIHTML
- $1,890.55格式的顯示
- django 設定日期顯示格式Django
- pl/sql developer中關於TIMESTAMP顯示格式的疑問和學習SQLDeveloper
- ultraedit高亮顯示pl/sqlSQL
- [20180628]顯示bbed x命令格式.txt
- PHP列印格式化顯示利器PHP
- Elements皮膚顯示HTML註釋HTML
- SAP SD 以PDF格式顯示BILLING的輸出格式
- [20230906]顯示最近統計分析的操作報表.txt
- c# 嵌入銳浪報表C#
- 時間格式化,顯示昨天、今天
- JSON 格式化 顯示到頁面中JSON
- Android MPAndroidChart LineChart 顯示資料格式化Android
- PHPstrom 配置 Laravel Log 格式日誌高亮顯示PHPLaravel
- linux系統lcd顯示jpg格式圖片Linux
- html2canvas生成圖片顯示不全HTMLCanvas
- element table 表頭顯示 tooltip
- navicat 表中文顯示? 解決
- 設計好的報表是如何在 web 上顯示的Web
- 報表的查詢皮膚怎麼顯示在左側?
- SAP WM 顯示TR ITEM的標準報表LX09
- SHOW PROCESSLIST 最多能顯示多長的 SQL?SQL
- Dynamics 365 Online fetchXml報表的顯示數量的限制與否XML
- 設定SAP標準報表顯示介面預設值的方式
- HTML————7、HTML文字格式化HTML
- HTML學習(3)(HTML字元格式)HTML字元
- WPF TextBlock根據值顯示不同的內容或格式BloC
- SAP Fiori應用裡日期格式的顯示奧祕
- Pytorch視覺化(顯示圖片)及格式轉換PyTorch視覺化
- 在JPEG圖片中嵌入HTMLHTML
- HTML5 自定義驗證資訊顯示方式HTML
- hive表查詢中文顯示亂碼Hive
- win10系統長日期格式顯示怎麼設定 win10系統設定長時間格式顯示的步驟Win10
- Excel2007工作表如何分視窗顯示?Excel2007工作表分視窗顯示的方法Excel
- 關於 SAP ABAP 報表的多語言顯示問題試讀版