导入分区表的某分区报错: ORA-39151: Table "SYSTEM"."T_PART" exists.

分区表的导出/导入实验过程如下:

1. 创建测试分区表

CREATE TABLE "SYSTEM"."T_PART" 
   ("OWNER" VARCHAR2(30), 
  "SEGMENT_NAME" VARCHAR2(81), 
  "PARTITION_NAME" VARCHAR2(30), 
  "SEGMENT_TYPE" VARCHAR2(18), 
  "SEGMENT_SUBTYPE" VARCHAR2(10), 
  "TABLESPACE_NAME" VARCHAR2(30), 
  "HEADER_FILE" NUMBER, 
  "HEADER_BLOCK" NUMBER, 
  "BYTES" NUMBER, 
  "BLOCKS" NUMBER, 
  "EXTENTS" NUMBER, 
  "INITIAL_EXTENT" NUMBER, 
  "NEXT_EXTENT" NUMBER, 
  "MIN_EXTENTS" NUMBER, 
  "MAX_EXTENTS" NUMBER, 
  "MAX_SIZE" NUMBER, 
  "RETENTION" VARCHAR2(7), 
  "MINRETENTION" NUMBER, 
  "PCT_INCREASE" NUMBER, 
  "FREELISTS" NUMBER, 
  "FREELIST_GROUPS" NUMBER, 
  "RELATIVE_FNO" NUMBER, 
  "BUFFER_POOL" VARCHAR2(7), 
  "FLASH_CACHE" VARCHAR2(7), 
  "CELL_FLASH_CACHE" VARCHAR2(7)
   )  partition by hash(segment_type)
( partition p1
, partition p2
, partition p3
, partition p4
);
insert into t_part select * from dba_segments;
commit;

 

2. 导出分区表

[oracle@rac1 expdp]$ expdp system/oracle  tables=t_part directory=expdp logfile=expdp_t_part.log job_name=1
...
. . exported "SYSTEM"."T_PART":"P1"                      144.7 KB     953 rows
. . exported "SYSTEM"."T_PART":"P2"                      31.17 KB     114 rows
. . exported "SYSTEM"."T_PART":"P3"                      118.1 KB     781 rows
. . exported "SYSTEM"."T_PART":"P4"                      466.4 KB    3604 rows
Master table "SYSTEM"."1" successfully loaded/unloaded


随后将T_PART表删除:

 

SQL> DROP TABLE T_PART PURGE;

 

3. 导入测试1(分区p2)

[oracle@rac1 expdp]$ impdp system/oracle directory=expdp dumpfile=expdat.dmp logfile=impdp_t_part2.log job_name=2  tables=t_part:p2
...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SYSTEM"."T_PART":"P2"                      31.17 KB     114 rows  <<<<<<<<===========只有分区p2数据被导入
Job "SYSTEM"."2" successfully completed at Sat Dec 27 12:30:50 2014 elapsed 0 00:00:05


此时,检查T_PART的表结构,可看到p1,p2,p3,p4分区都已被自动创建,因为导入时候会自动创建表结构,所有分区都是表的结构中一部分。

 

4. 导入测试2(分区p3)

[oracle@rac1 expdp]$ impdp system/oracle directory=expdp dumpfile=expdat.dmp logfile=impdp_t_part3.log job_name=3 tables=t_part:p3
...
ORA-39151: Table "SYSTEM"."T_PART" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Job "SYSTEM"."3" completed with 1 error(s) at Sat Dec 27 12:32:16 2014 elapsed 0 00:00:03

TABLE_EXISTS_ACTION默认是skiped,意为如果IMPDP检测到待导的表名已存在于数据中,则略过。添加参数重来一遍:

[oracle@rac1 expdp]$ impdp system/oracle directory=expdp dumpfile=expdat.dmp logfile=impdp_t_part3.log job_name=3  tables=t_part:p3 TABLE_EXISTS_ACTION=append
...
Processing object type TABLE_EXPORT/TABLE/TABLE
Table "SYSTEM"."T_PART" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SYSTEM"."T_PART":"P3"                      118.1 KB     781 rows
Job "SYSTEM"."3" successfully completed at Sat Dec 27 12:33:47 2014 elapsed 0 00:00:11


有关TABLE_EXISTS_ACTION参数的说明如下:

 

TABLE_EXISTS_ACTION={SKIP | APPEND | TRUNCATE | REPLACE}


The possible values have the following effects:
•
SKIP leaves the table as is and moves on to the next object. This is not a valid option if the CONTENT parameter is set to DATA_ONLY.

•
APPEND loads rows from the source and leaves existing rows unchanged.

•
TRUNCATE deletes existing rows and then loads rows from the source.

•
REPLACE drops the existing table and then creates and loads it from the source. This is not a valid option if the CONTENT parameter is set to DATA_ONLY.

 

至此,在分区表的导出导入实验中,通过添加TABLE_EXISTS_ACTION=APPEND来解决了ORA-39151。

可以将表的每个分区当作是一张表来理解。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值