如果表上存在有LOB数据类型的字段,而有时候我们需要将这些表和索引移动到别的表空间去,但是使用正常的alter index index_name rebuild tablespace_name的方法是行不通的,数据库会报错:ORA-02327: cannot create index on expression with datatype LOB。
在这种情况下要移动LOB索引,就必须要使用特定的方法来移动LOB索引。让我们举例来具体的看看:
先创建一个带有LOB字段的表test,默认的表空间是system:
SQL> CREATE TABLE test
2 (
3 NAME VARCHAR2(100 BYTE) NOT NULL,
4 OWNERNAME VARCHAR2(100 BYTE) NOT NULL,
5 STATUSPOLLCOMMAND VARCHAR2(100 BYTE),
6 DATAPOLLIOR BLOB
7 )
8 TABLESPACE system
9 LOGGING
10 LOB (DATAPOLLIOR) STORE AS
11 ( TABLESPACE system)
12 NOCACHE
13 NOPARALLEL;
Table created.
SQL> select tablespace_name from user_tables where table_name='TEST';
TABLESPACE_NAME
------------------------------
SYSTEM
SQL>select index_name,tablespace_name from user_indexes where table_name='TEST';
INDEX_NAME TABLESPACE_NAME
------------------------------ ------------------------------
SYS_IL0000006955C00004$$ SYSTEM
然后我们想移动test表到test表空间中去,如果只是移动带有LOB字段的表,那是没有问题的,因为表和LOB字段的存储是在两个不同的段上,移动的只是表的存储,LOB字段的存储还是没有变。
SQL> alter table test move tablespace test;
Table altered.
SQL> select tablespace_name from user_tables where table_name='TEST';
TABLESPACE_NAME
------------------------------
TEST
SQL> select index_name,tablespace_name from user_indexes where table_name='TEST';
INDEX_NAME TABLESPACE_NAME
------------------------------ ------------------------------
SYS_IL0000006955C00004$$ SYSTEM
但是如果想要把LOB的索引也移动到test表空间去,我们使用通常的办法来move,就会产生ORA-02327: cannot create index on expression with datatype LOB:
SQL> alter index SYS_IL0000006955C00004$$ rebuild tablespace test;
alter index SYS_IL0000006955C00004$$ rebuild tablespace test
ERROR at line 1:
ORA-02327: cannot create index on expression with datatype LOB
这种情况下,我们要移动LOB的索引就必须使用特定的语法来移动LOB的对象,具体的语法如下:
ALTER TABLE table_name MOVE
TABLESPACE new_tbsp
STORAGE(new_storage)
LOB (lobcol)
STORE AS lobsegment
(TABLESPACE new_tbsp
STORAGE (new_storage));
对于这个例子,我们使用如下的方法:
SQL> ALTER TABLE test MOVE
2 TABLESPACE test
3 LOB (DATAPOLLIOR) STORE AS
4 (TABLESPACE test);
Table altered.
SQL>select index_name,tablespace_name from user_indexes where table_name='TEST';
INDEX_NAME TABLESPACE_NAME
------------------------------ ------------------------------
SYS_IL0000006955C00004$$ TEST
由上面我们可以看到LOB的索引已经被移动到test表空间了。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/3704/viewspace-488901/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/3704/viewspace-488901/