####################################################################################################
#desc : 实现某schema下类似TEST_UNION(01-0n)的聚合统计
####################################################################################################
create table test as select * from TEST_UNION1 where 1=0;
set serveroutput on
truncate from test;
commit;
declare
cursor my_cursor is
select table_name from user_tables where table_name like 'TEST_UNION%' order by table_name;
v_table varchar2(50);
v_sql varchar2(4000);
begin
open my_cursor;
loop
fetch my_cursor into v_table;
exit when my_cursor%NOTFOUND;
dbms_output.put_line(v_table);
v_sql:='insert into test select * from '||v_table;
dbms_output.put_line(v_sql);
EXECUTE IMMEDIATE v_sql;
commit;
end loop;
close my_cursor;
end;
/
select * from test;
##########################################################################################################
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30182853/viewspace-2122690/
,如需转载,请注明出处,否则将追究法律责任。