|
|
发表于 2008/6/26 11:15:05
|
显示全部楼层
给大家一个最标准的SQL*PLUS格式的报表,全部是用select语句结合html语言写出来的,最后把下面的代码保存成后缀为sql格式的文件就可以了,注意:文件的编码存为“UTF-8”,要不然会SQL*PLUS报表会报错,然后在ERP系统中的“并发”,“可执行”中定义上就是一张SQL*PLUS报表。
def P_ORG_ID = '&1'
def P_SHIP_ID = '&2'
def P_VENDOR_ID = '&3'
def P_ITEM_FROM = '&4'
def P_ITEM_TO = '&5'
def P_CATEGORY_ID = '&6'
def P_DATE_FROM = '&7'
def P_DATE_TO = '&8'
Select '<table border="0" width="100%">',
'<tr><td colspan="4"><h1 align="center"><b>采购比例查询汇总表</b></h1></td></tr>',
'<tr><td width="20%">开始时间:'||to_char(to_date('&P_DATE_FROM','YYYY/MM/DD HH24:MI:SS'),'YYYY-MM-DD')||'</td><td width="20%">结束时间:'||to_char(to_date('&P_DATE_TO','YYYY/MM/DD HH24:MI:SS'),'YYYY-MM-DD')||'</td><td width="50%"></td><td width="10%"></td></tr>',
'</table>'
from DUAL;
SELECT '<table border="2" cellpadding="1" style="border-collapse: collapse" bordercolorlight="#000000" bordercolordark="#000000">'
FROM dual;
Select '<tr>',
'<th nowrap bgcolor="#FFFFFF">','工厂','</th>',
'<th nowrap bgcolor="#FFFFFF">','供应商名称','</th>',
'<th nowrap bgcolor="#FFFFFF">','物料编码','</th>',
'<th nowrap bgcolor="#FFFFFF">','物料名称','</th>',
'<th nowrap bgcolor="#FFFFFF">','物料类别','</th>',
'<th nowrap bgcolor="#FFFFFF">','计量单位','</th>',
'<th nowrap bgcolor="#FFFFFF">','采购总数量','</th>',
'<th nowrap bgcolor="#FFFFFF">','从该供应商的采购数量','</th>',
'<th nowrap bgcolor="#FFFFFF">','供应商数量占总数量的比例(%)','</th>',
'<th nowrap bgcolor="#FFFFFF">','原因说明','<th>',
'</tr>'
FROM dual;
Select '<tr>',
'<td nowrap style=''mso-number-format:"\@"''>',hou.name,'</td>',--工厂
'<td nowrap style=''mso-number-format:"\@"''>',pv.vendor_name,'</td>', --供应商名称
'<td nowrap style=''mso-number-format:"\@"''>',msi.SEGMENT1,'</td>', --物料编码
'<td nowrap style=''mso-number-format:"\@"''>',msi.DESCRIPTION,'</td>', --物料名称
'<td nowrap style=''mso-number-format:"\@"''>',mct.description,'</td>', --物料类别
'<td nowrap style=''mso-number-format:"\@"''>',a.unit_meas_lookup_code,'</td>', --计量单位
'<td nowrap>',sum(quantity_received) over (partition by a.item_id,a.unit_meas_lookup_code ),'</td>',--采购总数量
'<td nowrap>',quantity_received,'</td>', --从该供应商的采购数量
'<td nowrap>',round(quantity_received*100/ sum(quantity_received) over (partition by a.item_id,a.unit_meas_lookup_code ),5),'</td>', --供应商数量占总数量的比例
'<td nowrap style=''mso-number-format:"\@"''>','','</td>', --合同截止日
'</tr>'
from
(select ph.org_id,pl.item_id,ph.vendor_id,pl.unit_meas_lookup_code, sum(pll.quantity_received) quantity_received,pll.SHIP_TO_ORGANIZATION_ID
from po_headers_all ph ,po_lines_all pl,po_line_locations_all pll
where
ph.org_id=decode('&P_ORG_ID','-999999',ph.org_id,'&P_ORG_ID')
and pll.SHIP_TO_ORGANIZATION_ID=decode('&P_SHIP_ID','',pll.SHIP_TO_ORGANIZATION_ID,'&P_SHIP_ID')
and ph.vendor_id is not null
and ph.po_header_id=pl.po_header_id
and pll.po_header_id=pl.po_header_id
and pll.po_line_id=pl.po_line_id
and pll.quantity_received<>0
and ph.vendor_id=decode('&P_VENDOR_ID','',ph.vendor_id,'&P_VENDOR_ID')
and pll.last_update_date between decode('&P_DATE_FROM','',pll.last_update_date ,to_date('&P_DATE_FROM','YYYY/MM/DD HH24:MI:SS')) and decode('&P_DATE_TO','',pll.last_update_date ,to_date('&P_DATE_TO','YYYY/MM/DD HH24:MI:SS'))+1-1/(3600*24)
group by ph.org_id,pl.item_id,ph.vendor_id,pl.unit_meas_lookup_code,pll.SHIP_TO_ORGANIZATION_ID) a,
po_vendors pv,mtl_system_items_vl msi,hr_organization_units hou ,MTL_ITEM_CATEGORIES_V mic,MTL_CATEGORIES_TL mct
where a.vendor_id=pv.vendor_id
and a.item_id=msi.INVENTORY_ITEM_ID
and msi.ORGANIZATION_ID=(select organization_id from mtl_parameters where organization_code='MST')
and a.org_id=hou.organization_id
and mic.ORGANIZATION_ID=msi.ORGANIZATION_ID
and mic.CATEGORY_SET_NAME='YILI_物品类别集'
and mic.INVENTORY_ITEM_ID=msi.INVENTORY_ITEM_ID
and msi.SEGMENT1 between decode('&P_ITEM_FROM','',msi.SEGMENT1,'&P_ITEM_FROM') and decode('&P_ITEM_TO','',msi.SEGMENT1,'&P_ITEM_TO')
and mct.category_id=mic.CATEGORY_ID
and mct.language = userenv('LANG')
and mic.CATEGORY_ID=decode('&P_CATEGORY_ID','',mic.CATEGORY_ID,'&P_CATEGORY_ID');
SELECT '</table>' FROM dual; |
|