create table DataTable as
select 1 as c1,2 as c2 from dual
union all select 1,3 from dual
union all select 1,7 from dual
union all select 2,2 from dual
union all select 2,4 from dual
union all select 3,5 from dual
union all select 8,4 from dual
union all select 8,6 from dual
union all select 9,7 from dual;
create global temporary table WillOut(
C1 number(1),
C2 number(1))
on commit delete rows;
SQL
begin
for rec in (select c1,c2
from DataTable
order by c1,c2) Loop
insert into WillOut(C1,C2)
select rec.c1,rec.c2 from dual
where not exists(select 1 from WillOut b
where rec.c1 = b.C1
or rec.c2 = b.C2);
end Loop;
end;
/
select C1,C2
from WillOut
order by C1,C2;
解説
SQLだけでやるのは、
再帰的な処理があるので難しそうですね