四个脚本,用于表和索引转移表空间的操作

/*该脚本可以生成SQL,将SQL粘出来,就可以执行了*/

--转移普通表的表空间
select 'alter table ' || t1.table_name || ' move tablespace NEW_TBS;'
from user_all_tables t1
where t1.tablespace_name = 'OLD_TBS';

--转移分区表的表空间
select 'alter table ' || t1.table_name || move partition ' ||
t2.partition_name || ' tablespace NEW_TBS;' || chr(13) ||
'commit;'
from user_all_tables t1, user_tab_partitions t2
where t1.table_name = t2.table_name
and t2.tablespace_name = 'OLD_TBS';

--转移普通索引
select 'alter index' || t.INDEX_NAME || ' rebuild tablespace NEW_TBS;'
from user_indexes t
where t.index_type = 'NORMAL'
and t.DROPPED = 'NO'
and t.TABLE_NAME in
(select a.table_name
from user_all_tables a
where a.tablespace_name = 'OLD_TBS');

--转移分区索引
select 'alter index ' || t1.index_name || ' rebuild partition ' ||
t2.partition_name || 'tablespace NEW_TBS;'
from user_indexes t1, user_ind_partitions t2
where t1.INDEX_NAME = t2.index_name
and t2.tablespace_name = 'OLD_TBS'

原文地址:https://www.cnblogs.com/wingsless/p/2269401.html