当表具有自引用外键时,Oracle sqlldr

时间:2021-10-20 00:14:31

I am trying to make a simple database where one of the tables has a foreign key that references another column in that table.

我正在尝试创建一个简单的数据库,其中一个表具有引用该表中另一列的外键。

I've been able to load data correctly with SQL*Loader (using csv) before adding this constraint, but once I add it, I am not able to load data with SQL*Loader (all rows get rejected).

在添加此约束之前,我已经能够使用SQL * Loader(使用csv)正确加载数据,但是一旦我添加它,我就无法使用SQL * Loader加载数据(所有行都被拒绝)。

Is there some way to resolve this? I have been searching online for a few hours, and I haven't found anything very specific. I have found examples of direct path loads, but I don't want to assume direct path loading is set up on this oracle instance (the loading I use is conventional). Is there a set of steps I can follow to successfully load this data, or is there a parameter I can set to force the load of the data?

有什么方法可以解决这个问题吗?我一直在网上搜索几个小时,我没有发现任何非常具体的内容。我找到了直接路径加载的例子,但我不想假设在这个oracle实例上设置了直接路径加载(我使用的加载是常规的)。是否有一系列步骤可以成功加载此数据,或者是否有一个参数可以设置为强制加载数据?

1 个解决方案

#1


0  

This can be a quick workaround for the issue. Write a Unix/Bat script to do the following functions :

这可以是该问题的快速解决方法。编写Unix / Bat脚本来执行以下功能:

  1. Assume column1 is primary key field and column2 is self referencing foreign key field.
  2. 假设column1是主键字段,column2是自引用外键字段。
  3. Load the data into a temporary table without the self referencing constraints.
  4. 在没有自引用约束的情况下将数据加载到临时表中。
  5. Now insert into the table from temporary table but only distinct values of column1 should be inserted. Column2 should be populated as null in this statement.
  6. 现在从临时表插入表中,但只应插入不同的column1值。 Column2应在此语句中填充为null。
  7. Update all inserted records of the table with the self referencing column2. Since all the distinct values have already been entered it will not cause self referencing key error.
  8. 使用自引用column2更新表的所有插入记录。由于已经输入了所有不同的值,因此不会导致自引用键错误。

#1


0  

This can be a quick workaround for the issue. Write a Unix/Bat script to do the following functions :

这可以是该问题的快速解决方法。编写Unix / Bat脚本来执行以下功能:

  1. Assume column1 is primary key field and column2 is self referencing foreign key field.
  2. 假设column1是主键字段,column2是自引用外键字段。
  3. Load the data into a temporary table without the self referencing constraints.
  4. 在没有自引用约束的情况下将数据加载到临时表中。
  5. Now insert into the table from temporary table but only distinct values of column1 should be inserted. Column2 should be populated as null in this statement.
  6. 现在从临时表插入表中,但只应插入不同的column1值。 Column2应在此语句中填充为null。
  7. Update all inserted records of the table with the self referencing column2. Since all the distinct values have already been entered it will not cause self referencing key error.
  8. 使用自引用column2更新表的所有插入记录。由于已经输入了所有不同的值,因此不会导致自引用键错误。