oracle impdp content=data_only,如何指定先导入哪些表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39283715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
impdp content=data_only, how to specify which tables to import first
提问by jipot
I am trying to import my database using the command
我正在尝试使用命令导入我的数据库
impdp SYSTEM/password DIRECTORY=dmpdir DUMPFILE=database.dmp CONTENT=DATA_ONLY
This works at importing some parts of the data, however, I am getting an error:
这适用于导入数据的某些部分,但是,我收到一个错误:
ORA-02291: integrity constraint (SYSTEM.user_role_user_fk) violated - parent key not found
ORA-02291: 违反完整性约束 (SYSTEM.user_role_user_fk) - 未找到父键
Basically I need to import data from USER
first before I can import data from USER_ROLE
基本上我需要先导入数据,USER
然后才能从中导入数据USER_ROLE
Is there a way to specify order of operation or which table data to import first when using IMPDP?
使用 IMPDP 时,有没有办法指定操作顺序或首先导入哪个表数据?
EDIT: A bad solution I have found is to simply use the same impdp
statement as above twice. By doing it twice, I can import both USER
and USER_ROLE
, however there has to be an easier way to this.
编辑:我发现一个糟糕的解决方案是简单地使用与impdp
上面相同的语句两次。通过执行两次,我可以同时导入USER
and USER_ROLE
,但是必须有一种更简单的方法。
回答by Alex Poole
You could disable the constraints before importing, and re-enable them afterwards. You can do that with some dynamic SQL:
您可以在导入之前禁用约束,然后再重新启用它们。您可以使用一些动态 SQL 来做到这一点:
begin
for r in (
select 'ALTER TABLE "'||c.table_name||
'" DISABLE CONSTRAINT "'||c.constraint_name||'"' as cmd
from user_constraints c
where c.constraint_type = 'R'
)
loop
execute immediate r.cmd;
end loop;
end;
/
After you've run that, e.g. via SQL*Plus using a heredoc in a shell script, you can then run your impdp
command to import all of the tables in one go; and then run the same PL/SQL block but with ENABLE
instead of DISABLE
.
在您运行它之后,例如通过 SQL*Plus 在 shell 脚本中使用 heredoc,然后您可以运行您的impdp
命令以一次性导入所有表;然后运行相同的 PL/SQL 块,但使用ENABLE
而不是DISABLE
.
It's worth checking if you have any disabled constraints before you start. If you do the disable script could skip them based on their status, but the enable script wouldn't be able to tell whether they should be re-enabled or not; so you could either create a static enable script, or hard-code any exceptions you need.
在开始之前,值得检查是否有任何禁用的约束。如果你这样做,禁用脚本可以根据它们的状态跳过它们,但启用脚本将无法判断是否应该重新启用它们;所以你可以创建一个静态启用脚本,或者硬编码你需要的任何异常。