标题: impdp的TABLE_EXISTS_ACTION参数选项介绍 [打印本页] 作者: 万望 时间: 2020-6-14 03:39 标题: impdp的TABLE_EXISTS_ACTION参数选项介绍 impdp有一个参数选项TABLE_EXISTS_ACTION,help=y的解释为:
Action to take if imported object already exists.
Valid keywords are: APPEND, REPLACE, [SKIP] and TRUNCATE.
官方文档有句话:
“Only objects created by the Import will be remapped. In particular, the tablespaces for preexisting tables will not be remapped if TABLE_EXISTS_ACTION is set to SKIP, TRUNCATE, or APPEND.”。
仅仅是import创建的对象会被重新映射,如果使用了SKIP、TRUNCATE或APPEND,已存表对应的表空间不会有变化。
测试表:
create table test(id number);
insert into test values(1);
commit;
expdp user_exp/user_exp directory=EXPDP_DIR dumpfile=user_exp.dmp
insert into test values(2);
commit;
此时user_exp.dmp包含test表,且有一条id=1的记录。表中有id=1和id=2两条记录。
REPLACE选项:
impdp user_exp/user_exp TABLE_EXISTS_ACTION=replace dumpfile=user_exp.dmp directory=expdp_dir
SQL> select * from test;
ID
----------
1
此时表中只有id=1的记录,说明使用dmp覆盖了test表。
SKIP选项:
impdp user_exp/user_exp TABLE_EXISTS_ACTION=skip dumpfile=user_exp.dmp directory=expdp_dir
ORA-39151: Table "USER_EXP"."TEST" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
SQL> select * from test;
ID
----------
1
2
此时导入报错,说明是skip了已存在的对象,test表仍保持原状。
APPEND选项:
impdp user_exp/user_exp TABLE_EXISTS_ACTION=append dumpfile=user_exp.dmp directory=expdp_dir
ORA-39152: Table "USER_EXP"."TEST" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
SQL> select * from test;
ID
----------
1
2
1
虽然报错,但仍插入了test记录,报错提示了数据会append附加至已存在表中,但若有依赖关系的元数据,则会忽略。
TRUNCATE选项:
impdp user_exp/user_exp TABLE_EXISTS_ACTION=truncate dumpfile=user_exp.dmp directory=expdp_dir
ORA-39153: Table "USER_EXP"."TEST" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
SQL> select * from test;
ID
----------
1
报错提示对象已被truncate,但若有依赖关系的元数据,会被忽略。