programing

'+' 연산자를 사용하여 Oracle에서 FULL OUTER JOIN을 수행하는 방법은 무엇입니까?

cafebook 2023. 6. 27. 23:39
반응형

'+' 연산자를 사용하여 Oracle에서 FULL OUTER JOIN을 수행하는 방법은 무엇입니까?

FULL OUTER JOIN 또는 FULL JOIN과 같은 키워드를 사용하는 대신 '+' 연산자의 도움을 받아 'where' 절을 사용하여 Full Outer Join을 수행하려면 어떻게 해야 합니까?!

당신은 (적어도 직접적으로는) 할 수 없습니다.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

다음은 오라클에서 실행하여 결과를 직접 확인할 수 있는 예제입니다.

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

언급URL : https://stackoverflow.com/questions/10500020/how-to-perform-full-outer-join-in-oracle-using-operator

반응형