How to perform FULL OUTER JOIN in ORACLE using '+' operator?

前端 未结 2 1974
清酒与你
清酒与你 2021-02-13 04:05

Instead of using keywords like FULL OUTER JOIN or FULL JOIN, how can I perform full outer join using \'where\' clause with the help of \'+\' operator?!

相关标签:
2条回答
  • 2021-02-13 04:42

    Here's an example you can run in oracle to see the results for yourself as well.

    with 
    a as 
       (select 'A' tbl, level id from dual connect by level < 1000),
    b as 
       (select 'B' tbl, level + 500 id from dual connect by level < 1000)
    select a.tbl, a.id, b.tbl, b.id from a, b where a.id = b.id(+)
    union all
    select a.tbl, a.id, b.tbl, b.id from a, b where a.id(+) = b.id and a.id is null
    

    Is the same as:

    with 
    a as 
       (select 'A' tbl, level id from dual connect by level < 1000),
    b as 
       (select 'B' tbl, level + 500 id from dual connect by level < 1000)
    select a.tbl, a.id, b.tbl, b.id from a full outer join b on a.id = b.id
    
    0 讨论(0)
  • 2021-02-13 04:49

    You can't (at least directly). Oracle only supports a full outer join using SQL:1999 syntax.

    You can fake it by unioning two outer joins:

    select a.field1, b.field2
    from table_a a, table_b b
    where a.id = b.id(+)
    union all 
    select a.field1, b.field2
    from table_a a, table b b
    where a.id(+) = b.id
          and a.id is null
    

    It's a lot more readable using the SQL:1999 syntax:

    select a.field1, b.field2
    from table_a a full outer join table_b b
    on a.id = b.id
    
    0 讨论(0)
提交回复
热议问题