转载

oracle 表移动表空间

在oracle中有时需要把表移动到其他表空间中,下面是移动的步骤。
首先,使用下面的命令移动:
alter table table_name move tablespace tablespace_name;
然后,如果有索引的话必须重建索引:
alter index index_name rebuild tablespace tablespace_name;

需要注意的地方是:
1、若表中需要同时移动lob相关字段的数据,就必需用如下的含有特殊参数据的语句来完成。

alter table tb_name move tablespace tbs_name lob (col_lob1,col_lob2) store as(tablesapce tbs_name);

如果表特别多,可以生产一个执行的脚本。
select 'alter index '||OWNER||'.'||index_NAME||' rebuild tablespace tablespace_name;' from dba_indexes where OWNER='USERS';
select 'alter table '||OWNER||'.'||TABLE_NAME||' move tablespace tablespace_name;' from dba_tables where OWNER='USERS';

正文到此结束
Loading...