Oracle报表开发中遇到的问题记录(持续更新。。)

一、取报表查询时间的当月第一天、最后一天、上月等日期

WHERE FISCALYEAR=DECODE('||V_KJQJ||',''01'','||V_LKJND||','||V_KJND||')
AND FISCALPERIOD=TO_CHAR(ADD_MONTHS(TO_DATE('||V_KJQJ||', ''MM''),-1), ''MM'')
----如果是一月份的话,就是上一年
SELECT TRUNC(TO_DATE(''||V_CXSJ||'','yyyymmdd'), 'mm')FIRSTDAY,
LAST_DAY(TRUNC(TO_DATE(''||V_CXSJ||'','yyyymmdd'), 'mm'))LASTDAY
FROM DUAL
----根据传入的查询时间来确定每月第一天和最后一天

二、生成GUID_ID()

在建立临时表需要生成ID列,因此需要按格式生成sys_guid()

select substr(sys_guid(),1,8)||'-'||substr(sys_guid(),9,4)||
'-'||substr(sys_guid(),13,4)||'-'||substr(sys_guid(),17,4)
||'-'||substr(sys_guid(),21,12) from dual
生成:5CBC731F-F1F4-0422-E055-000000000001

SELECT SYS_GUID() FROM DUAL CONNECR BY ROWNUM<=10
将会生成10条不同的GUID

三、Oracle实现累加

使用 sum(sal) over (order by ename)... 查询员工的薪水“连续”求和,

注意over (order by ename)如果没有order by 子句,求和就不是“连续”的,


sum(sal) over (partition by deptno order by ename) 按部门“连续”求总和
sum(sal) over (partition by deptno) 按部门求总和
sum(sal) over (order by deptno,ename) 不按部门“连续”求总和

sum(sal) over () 不按部门,求所有员工总和,效果等同于sum(sal)。


详细见:http://www.cnblogs.com/umen/archive/2011/04/11/2012136.html


四、Oracle实现忽略条件

在Oracle多条件查询中包含了空值条件,可采用like 关系运算符
例如:select * from emp where deptno like to_char(变量1)||'%' and
ename like 变量2||'%' and
sal like to_char(变量3)||'%';

如果变量1、变量2、变量3中,有空值的话,就相当于没有这个条件一样了。


如下图中情况:



参考:https://zhidao.baidu.com/question/475872141.html
初学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>');
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值