move 如果含有LOB字段,则需要指定LOB列做move操作,对于索引需要rebuild
1.没有LOB字段
alter table xxxx move tablespace xxx;
alter index xxxx rebuild tablespace xxx;
如果表中含有LOB字段,则需要指定LOB列,LOB字段会自动创建数据段,索引段,如果尝试rebuild lob 索引时会报如下错误
alter index SYS_IL0002310750C00009$$ rebuild tablespace large_data
ORA-02327: cannot create index on expression with datatype LOB
2.含有LOB字段
对于LOB,如果通过数据字典user_ind_columns来查看是没有结果的,需要到user_lobs中去查找
SQL>select index_name,table_name from user_indexes where index_name=‘SYS_IL0002310750C00009$$’;
no rows selected
SQL>select table_name,column_name,tablespace_name,index_name from user_lobs where index_name=‘SYS_IL0002310750C00009$$’;
TABLE_NAME COLUMN_NAME TABLESPACE_NAME INDEX_NAME
APP_XML_CONFIG XML DATAL01 SYS_IL0002310750C00009$$
可以使用下面形式的语句来做LOB字段的迁移
alter table app_xml_config move tablespace large_data lob(xml) store as lobsegment(tablespace large_data);
注:
如果需要move上千张表,则使用如下SQL自动生成move tablespace 的语句
对表中的非LOB列进行move tablespace 操作
select ‘alter table ‘|| table_name||’ move tablespace large_data;’ from user_tables t where tablespace_name!=‘LARGE_DATA’ and exists ( select null from user_tab_cols where table_name=t.table_name and data_type not in (‘LONG’,‘BLOB’,‘CLOB’));
对表中的LOB列进行move tablespace 操作
select ‘alter table ‘||table_name||’ move tablespace large_data lob(’||column_name||’) store as ‘||SEGMENT_NAME||’(tablespace large_data);’ from user_lobs where index_name in (select index_name from user_indexes where tablespace_name!=‘LARGE_DATA’);
对表中的索引进行rebuild操作,因为LOB数据段已经做了move操作,所以索引LOB段无须做move操作
select ‘alter index ‘||index_name||’ rebuild tablespace large_data;’ from user_indexes where tablespace_name!=‘LARGE_DATA’;




