请问下 现在我的语句是这样的:select * from tableA
union all select * from tableB
union all select * from tableC
union all select * from tableD
....union all select * from tableZ总共20多句现在我单独每个语句的查询时间 少的不到一秒 多的不超过4秒
但是如果用这个语句这么一组装起来 花的时间就长了~这个语句可以怎么优化下 提高下速度 减少点时间呢..谢谢大家~
union all select * from tableB
union all select * from tableC
union all select * from tableD
....union all select * from tableZ总共20多句现在我单独每个语句的查询时间 少的不到一秒 多的不超过4秒
但是如果用这个语句这么一组装起来 花的时间就长了~这个语句可以怎么优化下 提高下速度 减少点时间呢..谢谢大家~
--建立一个表,结构与a表相同,用于存数据
create table t as select * from tablea where 1=0;
--使用过程来做
create or replace procedure pro_merge(table_name in varchar2)
as
begin
merge into t
using table_name t2 on
(t.id=t2.id)
when not matched then
insert (t.col_1,t.col_2,...)
values (t2.val_1,t2.val_2,...);
commit;
when others then
rollback;
end pro_merge;
create or replace procedure pro_merge(table_name in varchar2)
as
begin
merge into t
using table_name t2 on
(t.id=t2.id)
when not matched then
insert (t.col_1,t.col_2,...)
values (t2.val_1,t2.val_2,...);
commit;
exception
when others then
rollback;
end pro_merge;
如是数据量较大,使用分区表就行了,
不一定要分成这么多表。分别执行与union all执行实际时间差距有多大?先将这些表建立一个物化视图汇入一张表
看看速度如何?