数据是否同步仍未考证,但方法比较简单,可以用于参考:
思路:
1、创建中间表
CREATE TABLE A_T_NEW ("ID" VARCHAR2(32 BYTE) NOT NULL ENABLE, "DRIVERCODE" VARCHAR2(64 BYTE), "DRIVERTIME" TIMESTAMP (6), "LNG" VARCHAR2(32 BYTE), "LAT" VARCHAR2(32 BYTE), "IS_DELETED" VARCHAR2(20 BYTE) DEFAULT '0') PARTITION BY RANGE (DRIVERTIME)( PARTITION P1 VALUES LESS THAN (TO_TIMESTAMP('2016-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P2 VALUES LESS THAN (TO_TIMESTAMP('2016-04-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P3 VALUES LESS THAN (TO_TIMESTAMP('2016-07-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P4 VALUES LESS THAN (TO_TIMESTAMP('2016-10-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P5 VALUES LESS THAN (TO_TIMESTAMP('2017-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P6 VALUES LESS THAN (TO_TIMESTAMP('2017-04-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P7 VALUES LESS THAN (TO_TIMESTAMP('2017-07-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P8 VALUES LESS THAN (TO_TIMESTAMP('2017-10-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P9 VALUES LESS THAN (TO_TIMESTAMP('2018-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P10 VALUES LESS THAN (TO_TIMESTAMP('2018-04-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P11 VALUES LESS THAN (TO_TIMESTAMP('2018-07-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P12 VALUES LESS THAN (TO_TIMESTAMP('2018-10-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')), PARTITION P13 VALUES LESS THAN (MAXVALUE)); commit;
2、验证原表是否可以在线迁移
--验证原表是否可以在线迁移 exec dbms_redefinition.can_redef_table('tms','T_TMS_VEHICLE_DRIVER_REC');
3、在新开会话进行迁移,这里我没有新开会话,而是直接进行了迁移。
exec dbms_redefinition.start_redef_table('tms','T_TMS_VEHICLE_DRIVER_REC','A_T_NEW'); exec dbms_redefinition.sync_interim_table('tms','T_TMS_VEHICLE_DRIVER_REC','A_T_NEW'); exec dbms_redefinition.finish_redef_table('tms','T_TMS_VEHICLE_DRIVER_REC','A_T_NEW');
提交,会发现原有的表'T_TMS_VEHICLE_DRIVER_REC' 已添加分区完毕。但这时,原有PK,注释等并没有加入到新表。
4、更改主键(删除表,删除原有pk,如果不用同名约束,可以直接alter table)
drop table A_T_NEW purge ; alter table T_TMS_VEHICLE_DRIVER_REC add constraint T_TMS_VEHICLE_DRIVER_REC_PK primary key (id);
5、加注释(请预先保留SQL)
COMMENT ON COLUMN "TMS"."T_TMS_BILL"."ID" IS 'ID'; COMMENT ON COLUMN "TMS"."T_TMS_BILL"."BILL_CODE" IS '运单号'; .....