oracle报表如何开发,Oracle开发之报表函数

来统计全年的订单总额,这个函数会在记录集形成的过程中,每检索一条记录就执行一次,它总共执行了12次。这是非常费时的。实际上我们还有更简便的方法:

代码如下:

select month,

sum(tot_sales) month_sales,

sum(sum(tot_sales)) over(order by month

rows between unbounded preceding and unbounded following) win_sales,

rpt_sales

from orders

group by month;

MONTH MONTH_SALES WINDOW_SALES REPORT_SALES

---------- ----------- ------------ ------------

1 610697 6307766 6307766

2 428676 6307766 6307766

3 637031 6307766 6307766

4 541146 6307766 6307766

5 592935 6307766 6307766

6 501485 6307766 6307766

7 606914 6307766 6307766

8 460520 6307766 6307766

9 392898 6307766 6307766

10 510117 6307766 6307766

11 532889 6307766 6307766

12 492458 6307766 6307766

已选择12行。

over函数的空括号表示该记录集的所有记录都应该被列入统计的范围,如果使用了partition by则先分区,再依次统计各个分区。

二、RATIO_TO_REPORT函数:

报表函数特(窗口函数)特别适合于报表中需要同时显示详细数据和统计数据的情况。例如在销售报告中经常会出现这样的需求:列出上一年度每个月的销售总额、年底销售额以及每个月的销售额占全年总销售额的比例:

方法①:

代码如下:

100 * round(cust_sales / region_sales,2) || '%' Percent

from (select o.cust_nbr customer,

o.region_id region,

sum(o.tot_sales) cust_sales,

sum(sum(o.tot_sales)) over(partition by o.region_id) region_sales

from orders_tmp o

where o.year = 2001

group by o.region_id,o.cust_nbr) all_sales

where all_sales.cust_sales > all_sales.region_sales * 0.2;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值