有一段pl/sql,如下:begin
insert into target(...)
select * from table1;insert into target(...)
select * from table2;insert into target(...)
select * from table1
minus
select * from table2;insert into target(...)
select * from table2
minus
select * from table1;end;
请问该sql要怎么进行优化?
insert into target(...)
select * from table1;insert into target(...)
select * from table2;insert into target(...)
select * from table1
minus
select * from table2;insert into target(...)
select * from table2
minus
select * from table1;end;
请问该sql要怎么进行优化?
select * from table1 union all
select * from table2 union all
(select * from table1 minus
select * from table2)
select * from table1 union all
select * from table2 union all
(select * from table1 minus
select * from table2) union all
(select * from table2 minus
select * from table1)
这是一个办法,不过不算优化
select * from table1 union all
select * from table2 union all
select * from table1 a where not exists
(select 1 from table2 where col1=a.col1 and col2=a.col2...)
union all
select * from table2 b where not exists
(select 1 from table1 where col1=b.col1 and col2=b.col2...)这个其实也差不多
就是要插入table1,table2,然后再插入table1和table2不重复的部分
等待更好的办法
但是效率可能会更低
我想不出更好的办法