Oracle 12.2使用dbms_redefinition.redef_table过程来重定义表的存储属性,下面的例子将介绍使用redef_table过程来联机重定义表的存储属性,原始表名为test,存储在pm方案中:
SQL> desc pm.test Name Type Nullable Default Comments ------- --------- -------- ------- -------- AD_ID NUMBER(6) Y AD_TEXT CLOB Y
表test中的LOB数据类型列ad_text使用BasicFile LOB存储,执行下面的语句来创建索引test_idx
SQL> create index pm.test_idx on pm.test(ad_id) tablespace users; Index created
表test将按以下规则进行联机重定义:
.表使用高级行压缩来进行压缩
.表的存储表空间从users变为example
.索引压缩使用compress 1选项
.索引的存储表空间也从users变为example
.表中的LOB类型列ad_text使用compress high选项进行压缩
.LOB类型列ad_text的存储空间从users变为example
.LOB类型列ad_text变为SecureFiles LOB存储
联机重定义操作如下:
1.用要执行联机重定义操作的用户登录数据库
SQL> conn pm/pm@jypdb Connected.
2.执行dbms_redefinition.redef_table过程
SQL> exec dbms_redefinition.redef_table(uname =>'PM',tname =>'TEST',table_compression_type =>'ROW STORE COMPRESS ADVANCED',table_part_tablespace =>'EXAMPLE',index_key_compression_type =>'COMPRESS 1',index_tablespace =>'EXAMPLE',lob_compression_type =>'COMPRESS HIGH',lob_tablespace =>'EXAMPLE',lob_store_as =>'SECUREFILE'); PL/SQL procedure successfully completed.
3.查看重定义结果
SQL> set pagesize 0 SQL> set long 900000 SQL> select dbms_metadata.get_ddl(object_type =>'TABLE',name =>'TEST',schema => 'PM') from dual; CREATE TABLE "PM"."TEST" ( "AD_ID" NUMBER(6,0), "AD_TEXT" CLOB ) SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 ROW STORE COMPRESS ADVANCED LOGGING TABLESPACE "EXAMPLE" LOB ("AD_TEXT") STORE AS SECUREFILE ( TABLESPACE "EXAMPLE" ENABLE STORAGE IN ROW CHUNK 8192 NOCACHE LOGGING COMPRESS HIGH KEEP_DUPLICATES ) 1 row selected.