官方解释:The DBMS_REDEFINITION package provides an interface to perform. an online redefinition of tables.To achieve online redefinition, incrementally maintainable local materialized views are used. These logs keep track of the changes to the master tables and are used by the materialized views during refresh synchronization.
举例说明:
1、创建一张临时表
create table tmp_tab1
(
id int,
name varchar2(30)
);
alter table tmp_tab1 add constraint pk_id primary key (id);
insert into tmp_tab1
values(1,'aa');
insert into tmp_tab1
values(2,'bb');
commit;
2、看表能否重新定义:
BEGIN
DBMS_REDEFINITION.CAN_REDEF_TABLE('test_dba','tmp_tab1',DBMS_REDEFINITION.CONS_USE_PK);
END;
/
3:创建符合条件的中间表
drop table int_tmp_tab1;
create table int_tmp_tab1
as
select ID,
cast(0 as int) name1,
NAME
from tmp_tab1;
4:开始定义原表
BEGIN
DBMS_REDEFINITION.START_REDEF_TABLE('test_dba', 'tmp_tab1','int_tmp_tab1');
END;
/
5:对中间表规划好,建立原表的索引约束
alter table int_tmp_tab1 add constraint pk_id1 primary key (id);
6:进行同步表定义
begin
dbms_redefinition.sync_interim_table('test_dba','tmp_tab1','int_tmp_tab1');
end;
7:进行完成原表的修改
begin
dbms_redefinition.finish_redef_table( 'test_dba',
'tmp_tab1',
'int_tmp_tab1');
end;
8:删除中间表
drop table int_tmp_tab1 ;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23205405/viewspace-756545/ ,如需转载,请注明出处,否则将追究法律责任。