impdp之table_exists_action

来源:互联网 发布:淘宝女士秋季连衣裙 编辑:程序博客网 时间:2024/04/29 11:20

参考文档:1358280.1

TABLE_EXISTS_ACTION默认为:SKIP(但是如果设定了CONTENT=DATA_ONLY,那么默认的是APPEND)作用:定义了如果要导入的表已经存在,impdp的动作值及其含义:SKIP:不管已经存在的表,直接跳过APPEND:保持现有数据不变,导入源数据TRUNCATE:删掉现有数据,导入源数据REPLACE:删掉现有表,并重建,导入源数据测试:--环境用户:lm,lm2表:create table TEST(  ID         NUMBER,  UPDATETIME DATE)源端数据:insert into lm.test values(1,sysdate);insert into lm.test values(2,sysdate);SQL> select * from lm.test;         ID UPDATETIME---------- -----------         2 2016/9/26 1         1 2016/9/26 1导出:C:\Users\liming>expdp lm/lm directory=DATA_PUMP_DIR tables=lm.test dumpfile=test.dmpExport: Release 11.2.0.4.0 - Production on 星期一 9月 26 10:13:35 2016Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options启动 "LM"."SYS_EXPORT_TABLE_01":  lm/******** directory=DATA_PUMP_DIR tables=lm.test dumpfile=test.dmp正在使用 BLOCKS 方法进行估计...处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA使用 BLOCKS 方法的总估计: 64 KB处理对象类型 TABLE_EXPORT/TABLE/TABLE处理对象类型 TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS. . 导出了 "LM"."TEST"                                 5.421 KB       2 行已成功加载/卸载了主表 "LM"."SYS_EXPORT_TABLE_01"******************************************************************************LM.SYS_EXPORT_TABLE_01 的转储文件集为:  D:\APP\LIMING\ADMIN\ORCL\DPDUMP\TEST.DMP作业 "LM"."SYS_EXPORT_TABLE_01" 已于 星期一 9月 26 10:13:38 2016 elapsed 0 00:00:02 成功完成目标端数据: SQL> select * from lm2.test;         ID UPDATETIME---------- ----------- 1.SKIPC:\Users\liming>impdp lm/lm directory=DATA_PUMP_DIR tables=test remap_schema=lm:lm2 table_exists_action=skipImport: Release 11.2.0.4.0 - Production on 星期一 9月 26 10:23:06 2016Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options已成功加载/卸载了主表 "LM"."SYS_IMPORT_TABLE_01"启动 "LM"."SYS_IMPORT_TABLE_01":  lm/******** directory=DATA_PUMP_DIR tables=test remap_schema=lm:lm2 table_exists_action=skip处理对象类型 TABLE_EXPORT/TABLE/TABLE表 "LM2"."TEST" 已存在。由于跳过了 table_exists_action, 将跳过所有相关元数据和数据。处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA处理对象类型 TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS作业 "LM"."SYS_IMPORT_TABLE_01" 已于 星期一 9月 26 10:23:08 2016 elapsed 0 00:00:02 成功完成目标端数据: SQL> select * from lm2.test;         ID UPDATETIME---------- ----------- 2.APPENDC:\Users\liming>impdp lm/lm directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=APPEND remap_schema=lm:lm2Import: Release 11.2.0.4.0 - Production on 星期一 9月 26 10:41:39 2016Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options已成功加载/卸载了主表 "LM"."SYS_IMPORT_TABLE_01"启动 "LM"."SYS_IMPORT_TABLE_01":  lm/******** directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=APPEND remap_schema=lm:lm2处理对象类型 TABLE_EXPORT/TABLE/TABLE表 "LM2"."TEST" 已存在。由于附加了 table_exists_action, 数据将附加到现有表, 但是将跳过所有相关元数据。处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA. . 导入了 "LM2"."TEST"                                5.421 KB       2 行处理对象类型 TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS作业 "LM"."SYS_IMPORT_TABLE_01" 已于 星期一 9月 26 10:41:42 2016 elapsed 0 00:00:02 成功完成SQL> select * from lm2.test;        ID UPDATETIME---------- -----------         2 2016/9/26 1         1 2016/9/26 1再导入一次,查询数据:SQL> select * from lm2.test;        ID UPDATETIME---------- -----------         2 2016/9/26 1         1 2016/9/26 1         2 2016/9/26 1         1 2016/9/26 1果然是追加。那如果有主键呢??SQL> delete lm2.test where id=1; 2 rows deleted SQL> delete lm2.test where id=2 and rownum=1; 1 row deleted SQL> commit; Commit complete SQL> select * from lm2.test;         ID UPDATETIME---------- -----------         2 2016/9/26 1 SQL> alter table lm2.test add constraint pk_id primary key(id); Table altered导入:C:\Users\liming>impdp lm/lm directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=APPEND remap_schema=lm:lm2Import: Release 11.2.0.4.0 - Production on 星期一 9月 26 10:56:37 2016Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options已成功加载/卸载了主表 "LM"."SYS_IMPORT_TABLE_01"启动 "LM"."SYS_IMPORT_TABLE_01":  lm/******** directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=APPEND remap_schema=lm:lm2处理对象类型 TABLE_EXPORT/TABLE/TABLE表 "LM2"."TEST" 已存在。由于附加了 table_exists_action, 数据将附加到现有表, 但是将跳过所有相关元数据。处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATAORA-31693: 表数据对象 "LM2"."TEST" 无法加载/卸载并且被跳过, 错误如下:ORA-00001: 违反唯一约束条件 (LM2.PK_ID)处理对象类型 TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS作业 "LM"."SYS_IMPORT_TABLE_01" 已经完成, 但是有 1 个错误 (于 星期一 9月 26 10:56:40 2016 elapsed 0 00:00:03 完成)目标端数据:SQL> select * from lm2.test;         ID UPDATETIME---------- -----------         2 2016/9/26 1只要有一条违反了主键约束,就不会导入数据。3.truncate目标端数据:SQL> select * from lm2.test;         ID UPDATETIME---------- -----------         3 2016/9/26 1C:\Users\liming>impdp lm/lm directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=TRUNCATE remap_schema=lm:lm2Import: Release 11.2.0.4.0 - Production on 星期一 9月 26 12:19:33 2016Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options已成功加载/卸载了主表 "LM"."SYS_IMPORT_TABLE_01"启动 "LM"."SYS_IMPORT_TABLE_01":  lm/******** directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=TRUNCATE remap_schema=lm:lm2处理对象类型 TABLE_EXPORT/TABLE/TABLE表 "LM2"."TEST" 已存在且已截断。由于截断了 table_exists_action, 将加载数据, 但是将跳过所有相关元数据。处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA. . 导入了 "LM2"."TEST"                                5.421 KB       2 行处理对象类型 TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS作业 "LM"."SYS_IMPORT_TABLE_01" 已于 星期一 9月 26 12:19:37 2016 elapsed 0 00:00:03 成功完成目标端数据:SQL> select * from lm2.test;         ID UPDATETIME---------- -----------         2 2016/9/26 1         1 2016/9/26 1原有数据丢失。4.REPLACE目标端表信息:OWNER    OBJECT_NAME    LAST_DDL_TIMELM2    TEST    2016/9/26 12:21:40C:\Users\liming>impdp lm/lm directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=REPLACE remap_schema=lm:lm2Import: Release 11.2.0.4.0 - Production on 星期一 9月 26 12:24:38 2016Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options已成功加载/卸载了主表 "LM"."SYS_IMPORT_TABLE_01"启动 "LM"."SYS_IMPORT_TABLE_01":  lm/******** directory=DATA_PUMP_DIR dumpfile=test.dmp tables=lm.test TABLE_EXISTS_ACTION=REPLACE remap_schema=lm:lm2处理对象类型 TABLE_EXPORT/TABLE/TABLE处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA. . 导入了 "LM2"."TEST"                                5.421 KB       2 行处理对象类型 TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS作业 "LM"."SYS_IMPORT_TABLE_01" 已于 星期一 9月 26 12:24:42 2016 elapsed 0 00:00:03 成功完成查看数据:SQL> select * from lm2.test;         ID UPDATETIME---------- -----------         2 2016/9/26 1         1 2016/9/26 1查看表信息:OWNER    OBJECT_NAME    LAST_DDL_TIMELM2    TEST    2016/9/26 12:24:42重建了表。


0 0
原创粉丝点击