Oracle导入卡在table_data,【IMPDP】当导入数据时遭遇表已存时的应对手段——TABLE_EXISTS_ACTION参数...

当使用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官方文档中的描述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.logExport: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:29:17Copyright (c) 2003, 2005, Oracle.  All rights reserved.Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionsStarting "SEC"."SYS_EXPORT_SCHEMA_01":  sec/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec.logEstimate in progress using BLOCKS method...Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATATotal estimation using BLOCKS method: 3 MBProcessing object type SCHEMA_EXPORT/USERProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEProcessing object type SCHEMA_EXPORT/TABLE/INDEX/INDEXProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINTProcessing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICSProcessing object type SCHEMA_EXPORT/TABLE/COMMENT. . exported "SEC"."T"                                   2.259 MB   24360 rowsMaster table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded******************************************************************************Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:/expdp/20100401102917_sec.dmpJob "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:29:204.分别使用四中方式真实的感知一下具体效果用到的IMPDP语句统一汇总在这里,方便参考。impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=SKIPimpdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=APPENDimpdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=REPLACEimpdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=TRUNCATE1)默认行为SKIPsec@ora10g> select count(*) from t;COUNT(*)----------24360sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.logImport: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:50:41Copyright (c) 2003, 2005, Oracle.  All rights reserved.Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionsMaster table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloadedStarting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.logProcessing object type SCHEMA_EXPORT/USERORA-31684: Object type USER:"SEC" already existsProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEORA-39151: Table "SEC"."T" exists. All dependent metadata and data will be skipped due to table_exists_action of skipProcessing object type SCHEMA_EXPORT/TABLE/TABLE_DATAJob "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=SKIP2)APPEND方式sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=APPENDImport: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:51:32Copyright (c) 2003, 2005, Oracle.  All rights reserved.Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionsMaster table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloadedStarting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=APPENDProcessing object type SCHEMA_EXPORT/USERORA-31684: Object type USER:"SEC" already existsProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEORA-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 appendProcessing object type SCHEMA_EXPORT/TABLE/TABLE_DATA. . imported "SEC"."T"                                   2.259 MB   24360 rowsJob "SYSTEM"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 10:51:33此时表T的记录数翻倍。sec@ora10g> select count(*) from t;COUNT(*)----------487203)REPLACE方式sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=REPLACEImport: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:54:28Copyright (c) 2003, 2005, Oracle.  All rights reserved.Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionsMaster table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloadedStarting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=REPLACEProcessing object type SCHEMA_EXPORT/USERORA-31684: Object type USER:"SEC" already existsProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEProcessing object type SCHEMA_EXPORT/TABLE/TABLE_DATA. . imported "SEC"."T"                                   2.259 MB   24360 rowsJob "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at 10:54:29sec@ora10g> select count(*) from t;COUNT(*)----------243604)TRUNCATE方式sec@secDB /expdp$ impdp system/sys directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=TRUNCATEImport: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:54:55Copyright (c) 2003, 2005, Oracle.  All rights reserved.Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionsMaster table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloadedStarting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log TABLE_EXISTS_ACTION=TRUNCATEProcessing object type SCHEMA_EXPORT/USERORA-31684: Object type USER:"SEC" already existsProcessing object type SCHEMA_EXPORT/SYSTEM_GRANTProcessing object type SCHEMA_EXPORT/ROLE_GRANTProcessing object type SCHEMA_EXPORT/DEFAULT_ROLEProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMAProcessing object type SCHEMA_EXPORT/TABLE/TABLEORA-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 truncateProcessing object type SCHEMA_EXPORT/TABLE/TABLE_DATA. . imported "SEC"."T"                                   2.259 MB   24360 rowsJob "SYSTEM"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 10:54:56sec@ora10g> select count(*) from t;COUNT(*)----------243605.小结IMPDP的TABLE_EXISTS_ACTION参数相比IMP工具是一个进步,我们的控制手段得到加强,莫要固步自封。Good luck.secooler10.04.06-- The End --

你可能感兴趣的:(Oracle导入卡在table_data,【IMPDP】当导入数据时遭遇表已存时的应对手段——TABLE_EXISTS_ACTION参数...)