在Oracle中,关于语法 - 如何将(+)语法转换为现代常规JOIN?

时间:2015-08-27 19:07:01

标签: sql oracle left-join outer-join

假设我有一个像这样的FROM子句:

  FROM 

      apps.po_requisition_lines_all prl,  
      apps.po_requisition_headers_all prha,  
      po.po_req_distributions_all prda,  
      po.po_distributions_all pda,  
      po.po_headers_all pha 
  where 1=1  
      and prl.requisition_header_id= prha.requisition_header_id 
      and prl.requisition_line_id= prda.requisition_line_id 
      and prda.distribution_id= pda.req_distribution_id(+) 
      and pha.po_header_id(+)=pda.po_header_id 

如果我们想使用普通的JOIN语法,那么这种类型的OUTER JOIN如何转换?谢谢!

2 个答案:

答案 0 :(得分:1)

如果没有看到架构,我觉得很难,但这应该让你朝着正确的方向前进:

 FROM apps.po_requisition_lines_all prl 
 INNER JOIN apps.po_requisition_headers_all prha ON prl.requisition_header_id = prha.requisition_header_id 
 INNER JOIN po.po_req_distributions_all     prda ON prda.requisition_line_id  = prl.requisition_line_id
 LEFT  JOIN po.po_distributions_all         pda  ON prda.distribution_id      = pda.req_distribution_id 
-- I note from the example provided that this is a right join
-- Without seeing the schema, it looks to me as though it should be left
-- As I say say, without seeing the schema, I probably shouldn't pass comment
 RIGHT JOIN po.po_headers_all               pha  ON pha.po_header_id          = pda.po_header_id;

对于INNER JOIN,你可以说JOIN虽然我认为明确说INNER有助于提高可读性。我还注意到提供的示例有WHERE 1=1这是多余的。

答案 1 :(得分:1)

+ Outer Joins的旧版本,它与 + 的来源不同在平等签名之后或之前,但现在建议使用Join关键字代替+关于 + 签名,如果它出现:

= 之后:

select * from t1, t2
where t1.id=t2.id(+)

这意味着左外连接

select * from t1
left outer join t2 on t1.id=t2.id

= 之前:

select * from t1, t2
where t1.id(+)=t2.id

这意味着正确的外部加入

select * from t1
Right outer join t2 on t1.id=t2.id

没有 +

select * from t1, t2
where t1.id=t2.id

这意味着内部加入

select * from t1
join t2 on t1.id=t2.id
相关问题