1.创建分区表
create TABLESPACE job_part1 datafile size 10m;
create TABLESPACE job_part2 datafile size 10m;
create TABLESPACE job_part3 datafile size 10m;
create TABLESPACE job_part4 datafile size 10m;
CREATE TABLE fixf.MOCKDATA(
ID INT,JobTitle VARCHAR(500),
EmailAddress VARCHAR(500),
FirstNameLastName VARCHAR(500),
induct DATE)
partition by range(induct)
(
partition induction2016 values less than (to_date('2016-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) tablespace job_part1 ,
partition induction2017 values less than (to_date('2017-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) tablespace job_part2,
partition induction2018 values less than (to_date('2018-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) tablespace job_part3,
partition induction2019 values less than (to_date('2019-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) tablespace job_part4
);
select * from fixf.MOCKDATA PARTITION(induction2016);
select * from fixf.MOCKDATA PARTITION(induction2017);
select * from fixf.MOCKDATA PARTITION(induction2018);
select * from fixf.MOCKDATA PARTITION(induction2019);
insert into fixf.MOCKDATA values(1,'engine','123@163.com','ued',to_date('2015-02-01 03:00:00','yyyy-mm-dd hh24:mi:ss'));
insert into fixf.MOCKDATA values(1,'engine','123@163.com','ued',to_date('2016-02-01 03:00:00','yyyy-mm-dd hh24:mi:ss'));
insert into fixf.MOCKDATA values(1,'engine','123@163.com','ued',to_date('2017-02-01 03:00:00','yyyy-mm-dd hh24:mi:ss'));
insert into fixf.MOCKDATA values(1,'engine','123@163.com','ued',to_date('2018-02-01 03:00:00','yyyy-mm-dd hh24:mi:ss'));
commit;
2.导出分区数据
导出指定表
expdp fixf/12345 DIRECTORY=expdb file=fixf.dmp log=fixf.log compress=y feedback=20 tables=MOCKDATA;
导出分区
expdp fixf/12345 DIRECTORY=expdb file=fixf.dmp log=fixf.log compress=y feedback=20 tables=MOCKDATA:induction2017;
3.删除分区1数据并重新插入新的数据
delete fixf.MOCKDATA where induct BETWEEN to_date('2015-03-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and to_date('2015-04-01 00:00:00','yyyy-mm-dd hh24:mi:ss');
commit;
insert into fixf.MOCKDATA values(3,'cany','cany@qq.com','cany@jim',to_date('2015-04-01 05:00:00','yyyy-mm-dd hh24:mi:ss'));
commit;
此时induction2016分区只有1条刚刚插入的数据,之前的数据被删除
4.创建directory
create directory expdb as '/home/oracle/expdp';
grant read, write on directory expdb to fixf;
5.重新导入之前被删除的数据
impdp fixf/12345 file=fixf.dmp DIRECTORY=expdb buffer=1000000 TABLE_EXISTS_ACTION=append tables=fixf.MOCKDATA:induction2016;
异常处理: ORA-39171 ,ORA-01688
因为表空间不足导致导入的时候job 被挂起
ORA-39171: Job is experiencing a resumable wait.
Resumable error: ORA-01688: unable to extend table FIXF.MOCKDATA partition INDUCTION2016 by 1024 in tablespace JOB_PART1
Resumable stmt: INSERT /+ APPEND ENABLE_PARALLEL_DML PARALLEL(“MOCKDATA”,1)+/ INTO RELATIONAL(“FIXF”.”MOCKDATA” NOT XMLTYPE) (“ID”, “JOBTITLE”, “EMAILADDRESS”, “FIRSTNAMELASTNAME”, “INDUCT”) SELECT “ID”, “JOBTITLE”, “EMAILADDRESS”, “FIRSTNAMELASTNAME”, “INDUCT” FROM “FIXF”.”ET$0190FD7F0001” KU$
Resumable stmt status: SUSPENDED
Resumable stmt start: 08/01/21 21:23:51 stmt suspend: 08/01/21 21:23:51