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;