oracle中pr与po关系,关于PO 和PR 的联系问题
还有一种简单简单的办法,就是把pr_line和pr_header表连在一起,用括号括起来,作为一个子查询,去和po_line_locations_all做外关联
--以上是网友ideal 的提议.
Ideal 说:
你连接得不对。不知要连pr_line表,其他的地方也要加上外联结
--他说的原因.我想也是这样,一定是哪里有外连接,而我并不清楚.
所以还是采用他的建议;就是把pr_line和pr_header表连在一起,用括号括起来,作为一个子查询,去和po_line_locations_all做外关联
关于外连接以前只是字面上的理解,现在遇到了,才知道数据库的基础知识重要.再次感慨一下.[@more@]
以前一直想解决的就是输PO号,能购查询出来转化而来的PR号,最开始的研究结果是:
采购单找到请购单
通过采购单找到请购单的过程非常麻烦:
/* Formatted on 2006/03/30 14:35 (Formatter Plus v4.8.6) */
SELECTpod.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
WHEREprh.requisition_header_id=prl.requisition_header_id
ANDprod.requisition_line_id=prl.requisition_line_id
ANDprod.distribution_id = pod.req_distribution_id
ANDpoll.line_location_id=pod.line_location_id
ANDpoll.po_header_id=poh.po_header_id
ANDpoh.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--请购单行
再后来网友提示不需要采购单,请购单分布属性,那么就可以这样:
SELECTprh.segment1,pol.from_line_id,pol.*
FROMpo_lines_all pol,
po_headers_all poh,
po_line_locations_all poll,
po_requisition_headers_all prh,
po_requisition_lines_all prl
WHEREpol.po_header_id=poh.po_header_id
ANDpoll.line_location_id(+)=prl.line_location_id
andprh.requisition_header_id=prl.requisition_header_id
ANDpoll.po_line_id=pol.po_line_id
andpoll.po_header_id=poh.po_header_id
ANDpoh.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 语句,供借鉴:
SELECT DISTINCT (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 IS NULL
) --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
ORDER BY pl.line_num , pll.shipment_num, ph.segment1;
oracle中pr与po关系,关于PO 和PR 的联系问题相关推荐
- 如何控制让PO的数量不超过PR数量
我们在依据PR作PO,如何控制所作的PO的数量不能超过PR的数量? 答案就是修改系统消息的类型就可以. 我先建个PR,数量为10件,再由这个PR转PO,将数量由10件改为9件,系统不作提示,而由10件 ...
- 如何控制参照PR作PO时,PO的数量不能超过PR的数量
我们在依据PR作PO,如何控制所作的PO的数量不能超过PR的数量? 答案就是修改系统消息的类型就可以. 我先建个PR,数量为10件,再由这个PR转PO,将数量由10件改为9件,系统不作提示,而由10件 ...
- oracle中dbms_如何在DBMS中找到关系的最高范式?
oracle中dbms To find the highest normal form of a relation, you have to first understand the basics o ...
- PO系列之 PO中使用webService
一 前言 PO(/PI)是SAP公司的一个中间件产品,用来辅助连接SAP系统与外围系统. (当然外围系统之间也可以使用PO). 作为中间件,PO支持很多与系统交互的方式(RESTful, SOAP , ...
- Java中的VO,BO,PO,DO,DTO
随着现在后端编程标准化程度越来越高,各种编程模型层出不穷.作为Java开发人员,大部分人不免要接触VO,BO,PO,DO,DTO之类的,但很多人对这些概念一直以来都是云里雾里,团队开发过程中也总是 ...
- oracle中同个字段匹配多个like(or关系)实例解决方案
oracle中同个字段匹配多个like(or关系)实例解决方案 这样一段sql,要查询title这个字段里包含(150,160,85,1x,23,-,98)的数据 SELECTtitleFROMtes ...
- oracle 修改po税api_Oracle PO控制状态变更
PO 变更 tool->Control 内容说明 Cancel PO 取消整个 PO 信息,取消后不能再恢复 (只能在 PO Header 部分应用) Cancel PO Line 取消当前 P ...
- 删除PO交货计划行后PR对应的订购数量不更新问题_用户3231157403_新浪博客
客户提出一个issue. 当PO item 有两个PR时 删除其中一个行项目:PR10234539 然后查看PR 发现这里是不对,订购数量应该是0,没有更新 解决方案: 2265448 - Order ...
- oracle mssm,关于oracle 中的dmt_lmt_mssm_assm其间的关系
在了解dmt和lmt之前,先来简单的熟悉一下oracle数据库的逻辑结构,逻辑结构描速起来非常简单:表空间是由段(segment)组成的,段是由范围(extent)组成的,范围是由连续的(block) ...
最新文章
- 一文读懂tomcat组件--一个web服务器的架构演化史
- Linux安装docker-compose 1.27.4
- centos snmp配置_Cacti1.2.16最新版安装和配置(Shell一键安装)
- mysql主从1594错误_3分钟解决MySQL主从1594错误
- html支持的脚本语言,能不能让日志内容在支持html语言的同时支持一下脚本语言,拜托!拜托!...
- 手把手教你Axure-基本工具栏
- maven2打包不同jdk版本的包
- 这段 JavaScript 代码能挖出你所有的访问记录!
- CentOS 8安装logrotate切割日志
- LVS详解(六)——LVS DR模式实战
- OkHttp文件上传下载
- django 学习个人总结 之many_to_one
- 苹果ios、ipad加密视频播放器使用教程
- 基于SpringBoot的网页版进销存-2.0版本
- python连接sql server2008_Python 使用 pyodbc 连接 SQL Server 2008
- Tensorflow 笔记 Ⅳ——mnist手写数字识别
- 《开店有讲究》读书笔记
- MAC电脑实现微信多开
- 【C语言】动态内存开辟的使用『malloc』
- xinxin - 初步学习tkinter