标签:oracle
create table myPartition(id number,code varchar2(5),identifier varchar2(20));
insert into myPartition values(1,‘01‘,‘01-01-0001-000001‘);
insert into myPartition values(2,‘02‘,‘02-01-0001-000001‘);
insert into myPartition values(3,‘03‘,‘03-01-0001-000001‘);
insert into myPartition values(4,‘04‘,‘04-01-0001-000001‘);
commit;
alter table myPartition add constraint pk_test_id primary key (id);
--管理员权限执行begin
SQL> exec dbms_redefinition.can_redef_table(‘scott‘, ‘myPartition‘);
PL/SQL procedure successfully completed
–管理员权限执行end
create table t_temp(id number,code varchar2(5),
identifier varchar2(20)) partition by range(id)(
partition TAB_PARTOTION_01 values less than (2),
partition TAB_PARTOTION_02 values less than (3),
partition TAB_PARTOTION_03 values less than (4),
partition TAB_PARTOTION_04 values less than (5),
partition TAB_PARTOTION_OTHER values less THAN (MAXVALUE)
);
alter table t_temp add constraint pk_temp_id2 primary key (id);
--管理员权限执行sql命令行执行
exec dbms_redefinition.start_redef_table(‘scott‘, ‘myPartition‘, ‘t_temp‘);
--管理员权限执行sql命令行执行
这里dbms_redefinition包的start_redef_table模块有3个参数,分别是SCHEMA名字、原表的名字、中间表的名字。
select * from t_temp;
insert into myPartition values(5,‘05‘,‘05-01-0001-000001‘);
commit;
select * from myPartition;
select * from t_temp;
--管理员权限执行sql命令行执行,同步两边数据
exec dbms_redefinition.sync_interim_table(‘scott‘, ‘myPartition‘, ‘t_temp‘);
--管理员权限执行sql命令行执行
查询同步后的两边数据是否一致:
select * from myPartition;
select * from t_temp;
--管理员权限执行sql命令行执行,结束重定义
exec dbms_redefinition.finish_redef_table(‘scott‘, ‘myPartition‘, ‘t_temp‘);
--管理员权限执行sql命令行执行
select * from myPartition;
select * from t_temp;
select table_name, partition_name from user_tab_partitions where table_name = ‘myPartition‘;
select * from myPartition partition(TAB_PARTOTION_01);
drop table t_temp purge;
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:oracle
原文地址:http://blog.csdn.net/jameshadoop/article/details/48105297