很多人都知道在建立含有lob字段的表时,Oracle会自动为lob字段建立两个单独的segment,一个用来存放数据,另一个用来存放索引,并且它们都会存储在对应表指定的表空间中。但是当我们用alter table tb_name move tablespace tbs_name;来对表做空间迁移时只能移动非lob字段以外的数据,而如果需要同时移动lob相关字段的数据,就必需用如下的含有特殊参数据的语句来完成。
alter table tb_name move tablespace tbs_name
lob (col_lob1,col_lob2) store as(tablesapce tbs_name);
下面是一个具体的示例:
Connected to Oracle8i Enterprise Edition Release 8.1.7.0.0
Connected as scott
 
SQL> desc test_blob;
Name      Type         Nullable Default Comments
--------- ------------ -------- ------- --------
FILE_NAME VARCHAR2(25) Y                        
FILE_BIN  BLOB         Y                        
FILE_BIN2 BLOB         Y                        
 
SQL>
SQL> select t.segment_name, t.segment_type, t.tablespace_name
  2    from sys.user_segments t
  3    where t.segment_name like 'SYS_%'
  4  /
 
SEGMENT_NAME                  SEGMENT_TYPE       TABLESPACE_NAME
------------------------ - ----------------   --------------
SYS_IL0000025842C00003$$       LOBINDEX           SYSTEM
SYS_IL0000025842C00002$$       LOBINDEX           SYSTEM
SYS_LOB0000025842C00002$$      LOBSEGMENT         SYSTEM
SYS_LOB0000025842C00003$$      LOBSEGMENT         SYSTEM
 
6 rows selected
 
SQL> alter table test_blob move tablespace tools;
 
Table altered
 
SQL>
SQL> select t.segment_name, t.segment_type, t.tablespace_name
  2    from sys.user_segments t
  3    where t.segment_name like 'SYS_%'
  4  /
 
SEGMENT_NAME                       SEGMENT_TYPE       TABLESPACE_NAME
-------------------------    ----------------     --------------
SYS_IL0000025842C00003$$            LOBINDEX           SYSTEM
SYS_IL0000025842C00002$$            LOBINDEX           SYSTEM
SYS_LOB0000025842C00002$$           LOBSEGMENT         SYSTEM
SYS_LOB0000025842C00003$$           LOBSEGMENT         SYSTEM
 
6 rows selected
 
SQL> select t.segment_name, t.segment_type, t.tablespace_name
  2  from sys.user_segments t
  3  where t.segment_name like 'TEST_BLOB';
 
SEGMENT_NAME              SEGMENT_TYPE   TABLESPACE_NAME
------------------------  -------------  -----------------
TEST_BLOB                    TABLE              TOOLS
 
SQL> alter table test_blob move tablespace SYSTEM;
 
Table altered
 
SQL> ALTER TABLE test_blob MOVE
  2  TABLESPACE tools
  3  LOB (FILE_BIN,FILE_BIN2) STORE AS
  4  (TABLESPACE tools);
 
Table altered
 
SQL> select t.segment_name, t.segment_type, t.tablespace_name
  2  from sys.user_segments t
  3  where t.segment_name like 'SYS_%';
 
SEGMENT_NAME                   SEGMENT_TYPE       TABLESPACE_NAME
--------------------------- ------------------ ------------------------
SYS_IL0000025842C00003$$           LOBINDEX           TOOLS
SYS_IL0000025842C00002$$           LOBINDEX           TOOLS
SYS_LOB0000025842C00002$$          LOBSEGMENT         TOOLS
SYS_LOB0000025842C00003$$          LOBSEGMENT         TOOLS
 
6 rows selected