转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> SyBase >> 正文
关于PO 和PR 的联系问题         ★★★★

关于PO 和PR 的联系问题

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1426 更新时间:2009/4/22 23:09: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_linepr_header表连在一起用括号括起来作为一个子查询去和po_line_locations_all做外关联 --以上是网友ideal 的提议.   Ideal 说: 你连接得不对。不知要连pr_line表,其他的地方也要加上外联结 --他说的原因.我想也是这样,一定是哪里有外连接,而我并不清楚.   所以还是采用他的建议;就是把pr_linepr_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,         

[1] [2]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台