declare
old_owner varchar2(100) :=''; --定义原schema
old_table varchar2(100) :=''; --定义原表名
v_sql varchar2(2000) :=''; --定义拼接语句
--定义游标
cursor c_tab is select owner,table_name from
all_all_tables t where t.owner in ('AA','BB','CC');
begin
for v_tab in c_tab LOOP --for循环自带隐式关闭游标
old_owner :=v_tab.owner;
old_table :=v_tab.table_name;
v_sql :='create table twe.'||old_table||' as select * from '||old_owner||'.'||old_table
||' where rownum < 100';
begin
execute immediate v_sql;
exception when others then --当出现重复表名时跳过
null;
end;
end loop;
end;