简体   繁体   English

Oracle使用(+)进行左外部联接

[英]Oracle using (+) for left outer join

I have this query using outer left self join and it displays what I would expect: 我有使用外部左自我联接的此查询,它显示了我期望的结果:

SELECT c.date, u.user_id from order_detail_trans c
LEFT OUTER JOIN order_detail_trans u
ON u.trans_id = c.trans_id
AND u.trans_type = 'UPDATE DETAIL'

I am joining a table to itself because I want one of my columns (user_id) to be populated only for those rows with trans_type of 'UPDATE DETAIL'... but still need to display rows from this table where this is not the trans type. 我将一个表自身连接起来,因为我只希望为那些trans_type为“ UPDATE DETAIL”的行填充我的一列(user_id),但是仍然需要显示该表中的行,而这不是trans类型。 The above query seems to do the trick. 上面的查询似乎可以解决问题。 I get records with both trans_types, and those with 'UPDATE DETAIL' as trans_type display user_id 我同时获得了具有trans_types和以'UPDATE DETAIL'作为trans_type显示user_id的记录

I need this to work with the Oracle (+) syntax, here is what I have going off of this source -- https://chartio.com/resources/tutorials/left-and-right-joins-using-the-plus-sign-in-oracle/#performing-outer-joins-using-the-symbol : 我需要使用它来与Oracle(+)语法一起使用,这就是我从本源中获取的内容-https://chartio.com/resources/tutorials/left-and-right-joins-using-the-plus在符号Oracle中/#performing-outer-joins使用该符号

SELECT c.date, u.user_id from order_detail_trans c, order_detail_trans u
WHERE u.trans_id(+) = c.trans_id
AND u.trans_type = 'UPDATE DETAIL'

But this doesn't display rows with trans_type of anything other than 'UPDATE DETAIL' 但这不会显示带有trans_type而不是'UPDATE DETAIL'以外的行。

What would be the correct way of re-writing the first query with (+) syntax to render the same results? 用(+)语法重写第一个查询以呈现相同结果的正确方法是什么?

Need to include the (+) Operator on the Condition with the Literal 需要在文字条件上包含(+)运算符

The older outer join approach requires that you include the (+) operator for the condition on the literal. 旧的外部联接方法要求您为文字上的条件包括(+)运算符。

Just put your "retro" mental cap on and return back to the 90's. 只需戴上您的“复古”精神帽,然后回到90年代。 :) :)

Here is how it should look with this approach: 这种方法的外观如下:

SELECT
    c
.DATE,
 u.user_id
FROM
    order_detail_trans c,
    order_detail_trans u
WHERE
    u.trans_id (+) = c.trans_id
    AND   u.trans_type (+) = 'UPDATE DETAIL'

Here is an example with the tables, emp and dept : 这是表empdept的示例:

SCOTT@db>SELECT
  2      d.deptno,
  3      e.job
  4  FROM
  5      dept d
  6      LEFT OUTER JOIN emp e ON d.deptno = e.deptno
  7      and e.job = 'CLERK'
  8  GROUP BY
  9      d.deptno,
 10      e.job
 11  ORDER BY
 12      1,
 13      2;
  DEPTNO JOB     
      10 CLERK   
      20 CLERK   
      30 CLERK   
      40         


SCOTT@db>SELECT
  2      d.deptno,
  3      e.job
  4  FROM
  5      dept d,
  6      emp e
  7  WHERE
  8      d.deptno = e.deptno (+)
  9   AND e.job (+) = 'CLERK'
 10  GROUP BY
 11      d.deptno,
 12      e.job;
  DEPTNO JOB     
      20 CLERK   
      30 CLERK   
      10 CLERK   
      40    

Believe it or not, I believe most Oracle Applications shops just use this older outer join approach. 信不信由你,我相信大多数Oracle应用产品商店都只使用这种较旧的外部联接方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM