Oracle (+) outer join and constant values

后端 未结 4 2263
情书的邮戳
情书的邮戳 2021-02-09 13:08

I\'m running into an issue with which I can\'t figure out how to correctly configure a join. I\'m using reporting software that utilizes the (+) indicators in the WHERE clause f

4条回答
  •  执笔经年
    2021-02-09 13:59

    .The (+) operator tells Oracle that a predicate is part of an outer join rather than a filter predicate that can be applied after the join. Using the SQL 99 outer join syntax, the first query is equivalent to

    SELECT *
      FROM txn
           left outer join chk 
             on( txn.chk_id = chk.chk_id )
     WHERE txn.current = 'Y'
       AND chk.current = 'Y'
    

    while the second is equivalent to

    SELECT *
      FROM txn
           left outer join chk 
             on( txn.chk_id  = chk.chk_id AND
                 chk.current = 'Y')
     WHERE txn.current = 'Y'
    

    Logically, in the first case, you do the outer join but then all the rows where chk.current was NULL get filtered out. In the second case, the chk.current = 'Y' condition doesn't filter out any rows, it just controls whether a matching row is found in chk or whether a left outer join is performed.

提交回复
热议问题