[转自:http://space.itpub.net/519536/viewspace-631445]

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

真实感受一下这几种方式的效果,供参考。

1.IMPDP在线帮助中关于TABLE_EXISTS_ACTION参数的描述
TABLE_EXISTS_ACTION   Action to take if imported object already exists.
                      Valid keywords: (SKIP), APPEND, REPLACE and TRUNCATE.

2.Oracle官方文档中的描述
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_import.htm#sthref365
Oracle官方文档是根本,需研读。

3.使用EXPDP生成一份dump文件
sec@secDB /expdp$ expdp sec/sec directory=expdp_dir dumpfile=`date +"%Y%m%d%H%M%S"`_sec.dmp logfile=`date +"%Y%m%d%H%M%S"`_sec.log

Export: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:29:17

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Starting "SEC"."SYS_EXPORT_SCHEMA_01":  sec/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 3 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
. . exported "SEC"."T"                                   2.259 MB   24360 rows
Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:
  /expdp/20100401102917_sec.dmp
Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:29:20

4.分别使用四中方式真实的感知一下具体效果
用到的IMPDP语句统一汇总在这里,方便参考。
impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=SKIP
impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=APPEND
impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=REPLACE
impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=TRUNCATE

1)默认行为SKIP
sec@ora10g> select count(*) from t;

COUNT(*)
----------
     24360

sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log

Import: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:50:41

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"SEC" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "SEC"."T" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 10:50:42

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

2)APPEND方式
sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=APPEND

Import: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:51:32

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=APPEND
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"SEC" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39152: Table "SEC"."T" 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 "SEC"."T"                                   2.259 MB   24360 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 10:51:33

此时表T的记录数翻倍。
sec@ora10g> select count(*) from t;

COUNT(*)
----------
     48720

3)REPLACE方式
sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=REPLACE

Import: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:54:28

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=REPLACE
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"SEC" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SEC"."T"                                   2.259 MB   24360 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at 10:54:29

sec@ora10g> select count(*) from t;

COUNT(*)
----------
     24360

4)TRUNCATE方式
sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=TRUNCATE

Import: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:54:55

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=TRUNCATE
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"SEC" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39153: Table "SEC"."T" 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 "SEC"."T"                                   2.259 MB   24360 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 10:54:56

sec@ora10g> select count(*) from t;

COUNT(*)
----------
     24360

5.小结
IMPDP的TABLE_EXISTS_ACTION参数相比IMP工具是一个进步,我们的控制手段得到加强,莫要固步自封。

Good luck.

secooler
10.04.06

-- The End --

【IMPDP】当导入数据时遭遇表已存时的应对手段——TABLE_EXISTS_ACTION参数相关推荐

  1. HeidiSQL- csv 表格导入数据到 DB表

    一.背景 我们产品C 在测试过程中,需要创建DB表.并且需要在DB表中构造测试数据:测试数据可以通过我们测试团队开发的测试数据构造 生成csv文件,但如何将csv 中的数据插入DB表呢 ? 通过可视化 ...

  2. 解决iphone填写表单时,表单项获取焦点时往下拉屏,导致顶部标题栏下滑错位...

    $(function () {//解决iphone填写表单时,表单项获取焦点时往下拉屏,导致顶部标题栏下滑错位var u = navigator.userAgent;var isiOS = !!u.m ...

  3. impdp导入数据及创建表空间,删除表空间

    目录 注意: 一.删除表空间 1.删除用户 2.删除表空间 二.创建表空间 三.创建用户 四.impdp导入数据 1.建立虚拟文件夹 2.授权给文件夹 3.imp导入 注意: 1.impdp为数据泵导 ...

  4. 自定义组件使用el-dialog,且内含表单时,表单提交时字段报错undefined

    原因:初始化表单时,表单并没有拿到数据,渲染就会出错 解决方法:在自定义组件内通过v-if对数据的渲染加判断 具体操作如下: <my-component v-if="userInfoD ...

  5. Oracle创建scott用户导入数据查看emp表

    写在前面,这里我使用的是database19c, 而从12c开始oracle就不再提供已经创建好的scott用户,所以我们需要自行创建来测试. 流程: 过程十分简单,大概两三分钟就能做好 打开cmd, ...

  6. oracle数据磊导入数据,可传输表空间记载

    今天泡pub看到一个网友说到跨平台迁移表空间,把a库的表空间迁移到b库中,往常的可以通过exp和imp或者数据磊工具导入导出,记得在oracle concepts中提到了关于可传输表空间的功能,在or ...

  7. 批量导入数据到hive表中:假设我有60张主子表如何批量创建导入数据

    背景:根据业务需要需要把60张主子表批量入库到hive表. 创建测试数据: 1 def createBatchTestFile(): Unit = { 2 for (layer <- 0 to ...

  8. Hive数据导入——数据存储在Hadoop分布式文件系统中,往Hive表里面导入数据只是简单的将数据移动到表所在的目录中!...

    转自:http://blog.csdn.net/lifuxiangcaohui/article/details/40588929 Hive是基于Hadoop分布式文件系统的,它的数据存储在Hadoop ...

  9. 导入excel和json数据到数据库表中

    导入excel和json数据到数据库表中 1.清除表中数据 2.从excel中导入数据 3.导入JSON数据到表中 Mysql:5.7.33 工具:navicat 12 在所有操作之前先将数据库备份, ...

最新文章

  1. CodeSmith和PowerDesigner的使用安装和数据库创建(原创系列教程)
  2. 在Xshell 6开NumLock时按小键盘上的数字键并不能输入数字
  3. 机电传动控制大作业 第一阶段
  4. mysql把用户权限授予新用户_MySQL新建普通用户和库并授予新用户对新库的所有权限...
  5. 向量余弦值python_向量/矩阵的余弦值打印(元素明智的操作) 使用Python的线性代数
  6. javaee 中文帮助文档_从中游公司跳槽阿里必知:K8s、Nginx、Redis、微服务面试文档...
  7. Linux学习-YUM 在线升级机制
  8. 如何用sklearn创建机器学习分类器?这里有一份上手指南
  9. thinkpad分区win10_预装win10系统Thinkpad笔记本只有一个C盘怎么分区
  10. Qt之利用事件过滤器在QLabel上画框
  11. CPT自定义按钮导出(含参)
  12. win 安装 Xshell 5
  13. word2010 二级标题不跟随一级标题编号
  14. 卷帘快门(Rolling Shutter)与全局快门(Global Shutter)的区别
  15. nohup与前台后台操作
  16. 项目管理技术和工具TT
  17. 直播活动策划方案怎么做
  18. 2021计算机一级等级考试考前冲刺模拟试题及答案(WPS Office)
  19. 大华SDK+JAVA+4g网络摄像头进行二次开发
  20. 基于改进鲸鱼优化算法的WSN覆盖优化

热门文章

  1. TensorFlow ImportError: (‘Failed to import pydot. You must `pip install pydot`)
  2. 计算机组成原理课程内容,计算机组成原理课程教学大纲.doc.doc
  3. ThunderSoft Flash to HTML5中文版
  4. oracle 取前10条记录
  5. 错误笔记(1)——关于克隆虚拟机引发的后续问题
  6. 网页设计的12种颜色
  7. 原创:QQ群发言统计
  8. PyQt5——布局管理
  9. Linux监控平台 zabbix介绍和安装
  10. 141 springmvc中 转发 与 重定向