首页 > 数据库 > Oracle > 非分区表=>分区表(二)
--分别创建非分区表A,分区表B
A>create table a(id int);
Table created.
A>create table b(id int)
2 partition by range(id)
3 (partition p1 values less than(100),
4 partition p2 values less than(200),
5 partition p3 values less than(maxvalue))
6 /
Table created.
A>select TABLE_NAME,PARTITIONED from user_tables where table_name in ('A','B');
TABLE_NAME PAR
------------------------------ ---
A NO
B YES
包dbms_redefinition使用有3个步骤
1.start
2.sync
3.finish
另外有两点要注意:1要有相应权限,2是要重定义的表上一定要有主键(不知道为啥)
A>begin
2 DBMS_REDEFINITION.start_redef_table(uname => 'A',orig_table=>'A',int_table=>'B');
3 end;
4 /
begin
*
ERROR at line 1:
ORA-01031: insufficient privileges //缺少EXECUTE_CATALOG_ROLE角色
ORA-06512: at "SYS.DBMS_REDEFINITION", line 52
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1646
ORA-06512: at line 2
A>conn /as sysdba
Connected.
SYS>
SYS>begin
2 end;_REDEFINITION.start_redef_table(uname => 'A',orig_table=>'A',int_table=DBMS_REDEFINITION.start_redef_table(uname => 'A',orig_table=>'A',int_table=>'B');
3 end;
4 /
begin
*
ERROR at line 1:
ORA-12089: cannot online redefine table "A"."A" with no primary key
ORA-06512: at "SYS.DBMS_REDEFINITION", line 52
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1646
ORA-06512: at line 2
A>create index a_ind on a(id);
Index created.
A>alter table a add constraint a_pk primary key (id);
Table altered.
--有主键后start成功
SYS>/
PL/SQL procedure successfully completed.
SYS>BEGIN
2 dbms_redefinition.sync_interim_table(uname => 'A',orig_table => 'A',int_table =>
3 'B');
4 END;
5 /
PL/SQL procedure successfully completed.
SYS>BEGIN
dbms_redefinition.finish_redef_table(uname => 'A',orig_table => 'A',int_table =>
3 'B');
4 END;
5 /
PL/SQL procedure successfully completed.
--效果出来了
A>select TABLE_NAME,PARTITIONED from user_tables where table_name in ('A','B');
TABLE_NAME PAR
------------------------------ ---
A YES
B NO
和exchange相比,感觉包dbms_redefinition强调定义的转换,而exchange强调的是段的转换
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29646619/viewspace-1165390/ ,如需转载,请注明出处,否则将追究法律责任。