[an error occurred while processing this directive]
[an error occurred while processing this directive]
Oracle中如何移动LOB类型的索引
作者:coolyl
发表日期:2006-05-16 03:11
上一页1下一页
【IT168 技术文档】
如果表上存在有LOB数据类型的字段,而有时候我们需要将这些表和索引移动到别的表空间去,但是使用正常的alter index index_name rebuild tablespace_name的方法是行不通的,数据库会报错:ORA-02327: cannot create index on expression with datatype LOB。
如果表上存在有LOB数据类型的字段,而有时候我们需要将这些表和索引移动到别的表空间去,但是使用正常的alter index index_name rebuild tablespace_name的方法是行不通的,数据库会报错:ORA-02327: cannot create index on expression with datatype LOB。
在这种情况下要移动LOB索引,就必须要使用特定的方法来移动LOB索引。让我们举例来具体的看看:
先创建一个带有LOB字段的表test,默认的表空间是system:
SQL>CREATETABLE test
2 (
3 NAME VARCHAR2(100 BYTE) NOTNULL,
4 OWNERNAME VARCHAR2(100 BYTE) NOTNULL,
5 STATUSPOLLCOMMAND VARCHAR2(100 BYTE),
6 DATAPOLLIOR BLOB
7 )
8 TABLESPACE system
9 LOGGING
10 LOB (DATAPOLLIOR) STORE AS11 ( 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
SQL>altertable 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>alterindex SYS_IL0000006955C00004$$ rebuild tablespace test;
alterindex SYS_IL0000006955C00004$$ rebuild tablespace test
ERROR at line 1:
ORA-02327: cannot createindexon expression with datatype LOB
这种情况下,我们要移动LOB的索引就必须使用特定的语法来移动LOB的对象,具体的语法如下:
ALTERTABLE table_name MOVE
TABLESPACE new_tbsp
STORAGE(new_storage)
LOB (lobcol)
STORE AS lobsegment
(TABLESPACE new_tbsp
STORAGE (new_storage));
对于这个例子,我们使用如下的方法:
SQL>ALTERTABLE test MOVE
2 TABLESPACE test
3 LOB (DATAPOLLIOR) STORE AS4 (TABLESPACE test);
Table altered.
SQL>select index_name,tablespace_name from user_indexes where table_name='TEST';
INDEX_NAME TABLESPACE_NAME
------------------------------ ------------------------------SYS_IL0000006955C00004$$ TEST