王朝网络
分享
 
 
 

关于PO 和PR 的联系问题

王朝other·作者佚名  2006-04-08
宽屏版  字体: |||超大  

关于PO 和PR 的联系问题

以前一直想解决的就是输PO号,能购查询出来转化而来的PR 号,最开始的研究结果是:

采购单找到请购单

通过采购单找到请购单的过程非常麻烦:

/* Formatted on 2006/03/30 14:35 (Formatter Plus v4.8.6) */

SELECT pod.req_header_reference_num, prh.segment1

FROM

po_headers_all poh,

po_distributions_all pod,

po_req_distributions_all prod,

po_line_locations_all poll,

po_requisition_lines_all prl,

po_requisition_headers_all prh

WHERE prh.requisition_header_id = prl.requisition_header_id

AND prod.requisition_line_id = prl.requisition_line_id

AND prod.distribution_id = pod.req_distribution_id

AND poll.line_location_id = pod.line_location_id

AND poll.po_header_id = poh.po_header_id

AND poh.segment1 ='20500214'

涉及几个表相关联, 具体是:

po_headers_all poh, -- 采购单头

po_distributions_all pod, --采购单分部

po_req_distributions_all prod, --请购单分部

po_line_locations_all poll, --

--这个表做什么的,还不清楚, 但是如果连接采购单和请购单,必须通过此table

po_requisition_lines_all prl, --请购单行

po_requisition_headers_all prh --请购单行

再后来网友提示不需要采购单,请购单分布属性,那么就可以这样:

SELECT prh.segment1, pol.from_line_id, pol.*

FROM po_lines_all pol,

po_headers_all poh,

po_line_locations_all poll,

po_requisition_headers_all prh,

po_requisition_lines_all prl

WHERE pol.po_header_id = poh.po_header_id

AND poll.line_location_id(+)= prl.line_location_id

and prh.requisition_header_id=prl.requisition_header_id

AND poll.po_line_id = pol.po_line_id

and poll.po_header_id=poh.po_header_id

AND poh.segment1 ='20600018'

是可以满足要求了,那么,目前还有个问题就是, 如果PR转PO 后PO 又增加了行,那么如果连PR 查号码的时候就不能正确查出后增加的PO行,解决方法是外连接.上面的已经是外连接了,但是还是显示不出来,一定是还有外连接没有写.因为连接PO和PR 需要通过 po_line_locations_all 来连接, 那么就逐步测试一下:

Step 1:

SELECT pol.from_line_id, pol.* --prh.segment1,

FROM

po_headers_all poh,

po_line_locations_all poll,

-- po_requisition_headers_all prh,

-- po_requisition_lines_all prl,

/* full outer join */po_lines_all pol

WHERE pol.po_header_id = poh.po_header_id

--AND poll.line_location_id= prl.line_location_id

--and prh.requisition_header_id=prl.requisition_header_id

AND poll.po_line_id = pol.po_line_id

and poll.po_header_id=poh.po_header_id

AND poh.segment1 ='20600018'

可以正确查出po 的行.

还有一种简单简单的办法,就是把pr_line和pr_header表连在一起,用括号括起来,作为一个子查询,去和po_line_locations_all做外关联

--以上是网友ideal 的提议.

Ideal 说:

你连接得不对。不知要连pr_line表,其他的地方也要加上外联结

--他说的原因.我想也是这样,一定是哪里有外连接,而我并不清楚.

所以还是采用他的建议;就是把pr_line和pr_header表连在一起,用括号括起来,作为一个子查询,去和po_line_locations_all做外关联

关于外连接以前只是字面上的理解,现在遇到了,才知道数据库的基础知识重要.再次感慨一下.

顺遍说一下, 在9i 之前,oracle 不支持用单词写的外连接.如,

SELECT pol.from_line_id, pol.* --prh.segment1,

FROM

po_headers_all poh,

po_line_locations_all poll,

po_requisition_headers_all prh,

po_requisition_lines_all prl,

/* full outer join */po_lines_all pol

WHERE pol.po_header_id = poh.po_header_id

AND poll.line_location_id(+)= prl.line_location_id

and prh.requisition_header_id=prl.requisition_header_id

AND poll.po_line_id = pol.po_line_id

and poll.po_header_id=poh.po_header_id

AND poh.segment1 ='20600018'

其中 full outer join 在ERP应用的8.147 DB里并不被支持,所以还要写+那种origin 方法.

Step 2:

--step 2

SELECT prh.segment1,pol.from_line_id, pol.*

FROM

po_headers_all poh,

po_line_locations_all poll,

po_requisition_headers_all prh,

po_requisition_lines_all prl,

po_lines_all pol

WHERE pol.po_header_id = poh.po_header_id

AND poll.line_location_id(+)=(select prl.line_location_id

from prh, prl

where prh.requisition_header_id=prl.requisition_header_id)

AND poll.po_line_id = pol.po_line_id

and poll.po_header_id=poh.po_header_id

AND poh.segment1 ='20600018'

出现错误:

ORA-01799 a column may not be outer-joined to a subquery

Cause: expression(+) relop (subquery) is not allowed.

Action: Either remove the (+) or make a view out of the subquery. In V6 and before, the (+) was just ignored in this case.

Step 3:

--step 3

/* Formatted on 2006/04/07 14:01 (Formatter Plus v4.8.6) */

SELECT prl_line.segment1,pol.from_line_id, pol.* --prh.segment1,

FROM po_headers_all poh,

po_line_locations_all poll,

/*po_requisition_headers_all prh,

po_requisition_lines_all prl,*/

(SELECT prl.*, prh.segment1

FROM po_requisition_headers_all prh, po_requisition_lines_all prl

WHERE prh.requisition_header_id = prl.requisition_header_id) prl_line,

po_lines_all pol

WHERE pol.po_header_id = poh.po_header_id

AND poll.line_location_id= prl_line.line_location_id(+)

AND poll.po_line_id = pol.po_line_id

AND poll.po_header_id = poh.po_header_id

AND poh.segment1 ='20600018'

这样写是可以了

这一步是第二步的改善.关于外连接,如果那边的栏位缺少就在哪边写+号.

这个采购单的报表终于开发完了,学到了很多东西.

还没有解决的问题,如果使用动态参数输入工具列里的pl/sql 代码.因为主要攻外连接实现了请购单号的问题.但还存在不足,就是data block的分组问题,如果后加的采购单行要分别求和.

还要感慨一下,不是写报表时调field 和text(我以前粗略地称items) 的繁琐, 而数据库基础的重要性.pl/sql 的编程能力, 这些都必须提高!

以下是这个报表的sql 语句,供借鉴:

SELECTDISTINCT(ph.segment1) pono, pv.vendor_name vendor,

ph.fob_lookup_code fob, ph.ship_via_lookup_code via,

ap.NAME term_description,

NVL (pll.promised_date, pll.need_by_date) pr_date,

pl.line_num po_lineno, pll.shipment_num po_shipment,

-- msi.segment1 item_no,

NVL (msi.must_use_approved_vendor_flag,'N') avl_flag,

msi.segment1 || ' ' || pl.item_description descrip,

pll.quantity - NVL (pll.quantity_cancelled,0) qty,

NVL (pl.attribute1, pl.unit_meas_lookup_code) i_uom,

ph.currency_code currency, pl.unit_price u_price,

DECODE (ph.vendor_contact_id,

NULL,'',

pvc.last_name || pvc.first_name

) contact_name,

ROUND (( (pll.quantity - NVL (pll.quantity_cancelled,0))

* pl.unit_price

),

4

) line_total,

ph.comments v_desc, pll.line_location_id location_id,

pv.vendor_id v_vendor_id, ph.vendor_site_id v_site_id,

pl.item_id item_id, pl.line_type_id line_type,

prl_line.segment1 req_num

FROM po_vendors pv,

po_vendor_sites_all pvs,

po_vendor_contacts pvc,

po_headers_all ph,

po_lines_all pl,

ap_terms ap,

po_line_locations_all pll,

mtl_system_items msi,

(SELECT prl.*, prh.segment1

FROM po_requisition_headers_all prh,

po_requisition_lines_all prl

WHERE prh.requisition_header_id = prl.requisition_header_id) prl_line

WHERE pv.vendor_id = ph.vendor_id

AND pvs.vendor_site_id = ph.vendor_site_id

AND( ph.vendor_contact_id = pvc.vendor_contact_id

OR ph.vendor_contact_id ISNULL

) --best

AND ph.terms_id = ap.term_id

AND ph.org_id = NVL (:p_org_id,141)

AND ph.po_header_id = pl.po_header_id

AND pl.org_id = ph.org_id

AND pl.po_line_id = pll.po_line_id

AND pl.po_header_id = pll.po_header_id

AND pll.org_id = pl.org_id

AND pl.item_id = msi.inventory_item_id

AND pl.org_id = msi.organization_id

AND pll.quantity - NVL (pll.quantity_cancelled,0)>0

AND ph.segment1 IN

(NVL (:p_segment1, ph.segment1),

NVL (:p_segment2,''),

NVL (:p_segment3,''),

NVL (:p_segment4,''),

NVL (:p_segment5,''),

NVL (:p_segment6,''),

NVL (:p_segment7,''),

NVL (:p_segment8,''),

NVL (:p_segment9,''),

NVL (:p_segment10,''))

AND pll.line_location_id = prl_line.line_location_id(+)--notice here :outer join

AND pll.po_header_id = ph.po_header_id

ORDERBY pl.line_num , pll.shipment_num, ph.segment1;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有