impdp table_exists_action参数

impdp table_exists_action参数

1.当使用IMPDP完成数据库导入时,如遇到表已存在时,Oracle提供给我们如下四种处理方式:
a.忽略(SKIP,默认行为) 注意;无论表中的数据是否与要导入的表的数据量是否一致,都会skip。
b.在原有数据基础上继续增加(APPEND)
c.先DROP表,然后创建表,最后完成数据插入(REPLACE)
d.先TRUNCATE,再完成数据插入(TRUNCATE)。

2.使用EXPDP生成两份dump文件,一份导出scott下emp表的所有记录,另外一份导出scott下emp表中sal>3500的数据,此时只有一条数据。
导出命令如下:
expdp system/oracle directory=d1 dumpfile=`date +"%Y%m%d%H%M%S"`_scott_t1_full.dmp schemas=scott include=table:\"=\'T1\'\"  logfile=`date +"%Y%m%d%H%M%S"`_scott_t1.log
expdp system/oracle directory=d1 dumpfile=`date +"%Y%m%d%H%M%S"`_scott_t1_sal.dmp schemas=scott include=table:\"=\'T1\'\" query=t1:'"where sal > 3500"' logfile=`date +"%Y%m%d%H%M%S"`_scott_t1.log

2.1.导出scott下emp表中所有的数据
[oracle@test01 ~]$ expdp system/oracle directory=d1 dumpfile=`date +"%Y%m%d%H%M%S"`_scott_t1_full.dmp schemas=scott include=table:\"=\'T1\'\"  logfile=`date +"%Y%m%d%H%M%S"`_scott_t1.log

Export: Release 11.2.0.4.0 - Production on Wed Oct 12 19:11:04 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/******** directory=d1 dumpfile=20161012191104_scott_t1_full.dmp schemas=scott include=table:"='T1'" logfile=20161012191104_scott_t1.log 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."T1"                                8.570 KB      14 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/20161012191104_scott_t1_full.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Oct 12 19:11:30 2016 elapsed 0 00:00:20


2.2.导出scott下emp表中sal>3500的数据
[oracle@test01 ~]$ expdp system/oracle directory=d1 dumpfile=`date +"%Y%m%d%H%M%S"`_scott_t1_sal.dmp schemas=scott include=table:\"=\'T1\'\" query=t1:'"where sal > 3500"' logfile=`date +"%Y%m%d%H%M%S"`_scott_t1.log

Export: Release 11.2.0.4.0 - Production on Wed Oct 12 19:13:22 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/******** directory=d1 dumpfile=20161012191322_scott_t1_sal.dmp schemas=scott include=table:"='T1'" query=t1:"where sal > 3500" logfile=20161012191322_scott_t1.log 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."T1"                                8.039 KB       1 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/20161012191322_scott_t1_sal.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Oct 12 19:13:40 2016 elapsed 0 00:00:15

导出的两份dmp文件如下
[oracle@test01 ~]$ ls -lrt
total 368
-rw-r-----. 1 oracle oinstall 184320 Oct 12 19:11 20161012191104_scott_t1_full.dmp
-rw-r-----. 1 oracle oinstall 184320 Oct 12 19:13 20161012191322_scott_t1_sal.dmp

3.使用四种不同的参数,对比不同参数的不同结果。
sqlpus / as sysdba
conn kang/oracle
SQL> select count(*) from t1 ;

  COUNT(*)
----------
14

SQL> select * from t1 where sal>3500 ;

     EMPNO ENAME      JOB       MGR HIREDATE    SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7839 KING       PRESIDENT   17-NOV-81   5000   10

SQL> delete from t1 where sal>3500 ;

1 row deleted.

SQL> commit ;

Commit complete.


SQL> select * from t1 where sal>3500 ;

no rows selected

SQL> select count(*) from t1 ;

  COUNT(*)
----------
13

impdp system/oracle directory=d1 dumpfile=20161012191322_scott_t1_sal.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang 
等同于
impdp system/oracle directory=d1 dumpfile=20161012191322_scott_t1_sal.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=SKIP


导入过程如下:
[oracle@test01 ~]$ impdp system/oracle directory=d1 dumpfile=20161012191322_scott_t1_sal.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang

Import: Release 11.2.0.4.0 - Production on Wed Oct 12 19:49:44 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=d1 dumpfile=20161012191322_scott_t1_sal.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang 
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "KANG"."T1" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Wed Oct 12 19:49:49 2016 elapsed 0 00:00:03

SQL> select count(*) from t1 ;

  COUNT(*)
----------
13

结论:当参数table_exists_action=skip  即为忽略时(SKIP,默认行为),无论表中的数据是否与要导入的表的数据量是否一致,都会skip。

使用TABLE_EXISTS_ACTION的四种参数进行测试,测试结果如下

impdp system/oracle directory=d1 dumpfile=20161012191322_scott_t1_sal.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=SKIP
impdp system/oracle directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=APPEND
impdp system/oracle directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=REPLACE
impdp system/oracle directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=TRUNCATE

1)默认行为SKIP
SQL> select count(*) from t1 ;

  COUNT(*)
----------
13

导入数据(此时导入的数据只有一天记录就是sal>3500的那条数据)
[oracle@test01 ~]$ impdp system/oracle directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang

Import: Release 11.2.0.4.0 - Production on Wed Oct 12 19:24:51 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang 
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "KANG"."T1" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Wed Oct 12 19:24:56 2016 elapsed 0 00:00:03

上面的行为与下面一条显示的指定“SKIP”效果是一样的,不赘述。
sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=SKIP

SQL> select count(*) from t1 ;

  COUNT(*)
----------
13

2)APPEND方式
[oracle@test01 ~]$ impdp system/oracle directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=APPEND

Import: Release 11.2.0.4.0 - Production on Wed Oct 12 19:26:42 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=APPEND 
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Table "KANG"."T1" 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 SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "KANG"."T1"                                 8.570 KB      14 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Wed Oct 12 19:26:51 2016 elapsed 0 00:00:07

此时表T的记录数出入了14条记录,此时一共会有27条数据。
SQL> select count(*) from t1 ;

  COUNT(*)
----------
27

3)REPLACE方式
[oracle@test01 ~]$ impdp system/oracle directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=REPLACE

Import: Release 11.2.0.4.0 - Production on Wed Oct 12 19:28:38 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=REPLACE 
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "KANG"."T1"                                 8.570 KB      14 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Wed Oct 12 19:28:44 2016 elapsed 0 00:00:05

SQL> select count(*) from t1 ;

  COUNT(*)
----------
14

4)TRUNCATE方式
[oracle@test01 ~]$ impdp system/oracle directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=TRUNCATE

Import: Release 11.2.0.4.0 - Production on Wed Oct 12 19:29:29 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=d1 dumpfile=20161012191104_scott_t1_full.dmp logfile=20100401102917_scott_impdp.log remap_schema=scott:kang TABLE_EXISTS_ACTION=TRUNCATE 
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Table "KANG"."T1" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "KANG"."T1"                                 8.570 KB      14 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Wed Oct 12 19:29:37 2016 elapsed 0 00:00:06

SQL> select count(*) from t1 ;


  COUNT(*)
----------
14

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值