使用SQLPLUS生成HTML报表

我们可以在SQLPLUS中手工运行AWR,ASH的脚本生成HTML报表,下面来简单讲讲怎么利用SQLPLUS来生成HTML报表

在SQLPLUS中有个命令(具体可以参考官方文档SQLPLUS部分)

SET MARK[UP] HTML [ON | OFF] [HEAD text] [BODY text] [TABLE text] [ENTMAP {ON | OFF}] [SPOOL {ON | OFF}] [PRE[FORMAT] {ON | OFF}]

一:首先在SQLPLUS中设置

set mark html on spool on  entmap off  pre off

这样设置过后,利用spool 导出为htmlSQLPLUS将会自动的为我们创建HTML格式,

注意:如果设置pre on,那么输出的不是HTML格式,默认为off,

entmap 默认为on ,它会将>换成HTML中的&gt来显示,所以我将其设置为off

二:为了格式化输出,我们需要对输出内容格式化

set echo off                         这样设置之后不会在HTML报表中显示执行过的SQL语句

set feedback off                  这样设置过后不会在HTML报表中显示已经处理多少行

set heading on                   设置标题显示

set termout off                    关闭在屏幕上的输出,这样可以加快spool执行速度

set linesize 200    设置行宽度为120

set pagesize 1000             设置一页显示1000

set trimout off                    去掉 每行后面多余的空格

:利用spool 输出为 *.html

spool c:/test.html

四:写下要执行的SQL语句

五:spool off

例如要查询表空间利用率,并将结果输出为HTML报表格式:

将下面的语句保存为一个SQL脚本,然后在SQLPLUS中调用

SET MARKUP HTML ON SPOOL ON pre off entmap off
SET ECHO OFF
SET TERMOUT OFF
SET TRIMOUT OFF
set feedback off
set heading on
set linesize 200
set pagesize 10000
col tablespace_name format a15
col total_space format a10
col free_space format a10
col used_space format a10
col used_rate format 99.99
spool c:/test.html
select a.tablespace_name,a.total_space_Mb||'m' total_space,b.free_space_Mb||'m'

free_space,a.total_space_Mb-b.free_space_Mb||'m' used_space,
(1-(b.free_space_Mb/a.total_space_Mb))*100 used_rate,a.total_blocks,b.free_blocks from                    
(select tablespace_name,sum(bytes)/1024/1024 total_space_Mb,sum(blocks) total_blocks from dba_data_files

group by tablespace_name) a,
(select tablespace_name, sum((bytes)/1024/1024) free_space_Mb,sum(blocks) free_blocks from dba_free_space

group by tablespace_name) b
where a.tablespace_name=b.tablespace_name order by used_rate desc;
spool off
SQL> @test;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
初学oracle报表开发笔记 -- process report output('<HTML xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel">'); output('<head>'); output('<title>库存现有量报表</title>'); output('<style>'); output('body,table{font-size:13px;font-family:"Book Antiqua","Segoe UI", Tahoma, "Trebuchet MS", verdana, helvetica, arial, sans-serif, Georgia;}.text {mso-number-format:"\@";}.retnum {mso-number-format:"0\.00";}'); output('</style>'); output('</head>'); output('<body>'); output('<h2 align=center><B>库存现有量报表</B></h2>'); output('<table width=600 border=0 bordercolor=black>'); output(' <tr>'); output('<th align=right>OU:</th>'); output('<td align=left>' || g_ou_name || '</td>'); output('<th align=right>组织:</th>'); output('<td align=left>' || l_organization_name || '</td>'); output(' </tr>'); output('</table>'); output('<table width=1800 border=1 bordercolor=black>'); output(' <tr>'); output('<th rowspan=1 width=50>库存组织编码</th>'); output('<th rowspan=1 width=50>库存组织说明</th>'); output('<th rowspan=1 width=50>子库编码</th>'); output('<th rowspan=1 width=50>子库说明</th>'); output('<th rowspan=1 width=50>物品编码</th>'); output('<th rowspan=1 width=50>物品说明</th>'); output('<th rowspan=1 width=50>批次</th>'); output('<th rowspan=1 width=50>库存量 </th>'); output('<th rowspan=1 width=50>最小库存量</th>'); output('<th rowspan=1 width=50>最大库存量</th>'); output(' </tr>'); FOR cl IN (select OOD.ORGANIZATION_CODE, --库存组织编码 OOD.ORGANIZATION_NAME, --库存组织说明 MSA.SECONDARY_INVENTORY_NAME subinventory_code, --子库编码 MSA.DESCRIPTION subinventory_name, --子库说明 MSIV.SEGMENT1 item_no, --物品编码 MSIV.DESCRIPTION item_desc, --物品说明 MOQD.LOT_NUMBER, --批次 sum(MOQD.Primary_Transaction_Quantity) Primary_Transaction_Quantity, --库存量 MSIV.MIN_MINMAX_QUANTITY, --最小库存量 MSIV.MAX_MINMAX_QUANTITY --最大库存量 from mtl_onhand_quantities_detail moqd, ORG_ORGANIZATION_DEFINITIONS OOD, mtl_subinventories_all_v MSA, MTL_SYSTEM_ITEMS_VL MSIV where moqd.inventory_item_id = msiv.INVENTORY_ITEM_ID and moqd.organization_id = msiv.ORGANIZATION_ID and moqd.organization_id = ood.ORGANIZATION_ID and moqd.subinventory_code = msa.SECONDARY_INVENTORY_NAME and moqd.organization_id = msa.ORGANIZATION_ID group by OOD.ORGANIZATION_CODE, OOD.ORGANIZATION_NAME, MSA.SECONDARY_INVENTORY_NAME, MSA.DESCRIPTION, MSIV.SEGMENT1, MSIV.DESCRIPTION, MOQD.LOT_NUMBER, MSIV.MIN_MINMAX_QUANTITY, MSIV.MAX_MINMAX_QUANTITY) LOOP output(' <tr>'); output(' <td align=left><font size=1>' || cl.ORGANIZATION_CODE || '</font></td>'); output(' <td align=left><font size=1>' || cl.ORGANIZATION_NAME || '</font></td>'); output(' <td align=left><font size=1>' || cl.subinventory_code || '</font></td>'); output(' <td align=left><font size=1>' || cl.subinventory_name || '</font></td>'); output(' <td align=left><font size=1>' || cl.item_no || '</font></td>'); output(' <td align=left><font size=1>' || cl.item_desc || '</font></td>'); output(' <td align=left><font size=1>' || cl.LOT_NUMBER || '</font></td>'); output(' <td align=left><font size=1>' || cl.Primary_Transaction_Quantity || '</font></td>'); output(' <td align=left><font size=1>' || cl.MIN_MINMAX_QUANTITY || '</font></td>'); output(' <td align=left><font size=1>' || cl.MAX_MINMAX_QUANTITY || '</font></td>'); output(' </tr>');

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值