16

除了使用 FULL OUTER JOIN 或 FULL JOIN 之类的关键字,如何在“+”运算符的帮助下使用“where”子句执行完全外部连接?!

4

2 回答 2

22

你不能(至少直接)。Oracle 仅支持使用 SQL:1999 语法的完全外连接。

您可以通过联合两个外部联接来伪造它:

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

使用 SQL:1999 语法更具可读性:

select a.field1, b.field2
from table_a a full outer join table_b b
on a.id = b.id
于 2012-05-08T13:59:47.603 回答
3

这是一个示例,您也可以在 oracle 中运行以查看结果。

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

是相同的:

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
于 2012-05-08T15:09:50.120 回答