I have the following table in my Oracle database (19c):
CREATE TABLE debtors (
bankruptID NUMBER NOT NULL,
category VARCHAR2(50) NOT NULL,
lastname VARCHAR2(100),
firstname VARCHAR2(80),
birthdate DATE,
birthplace VARCHAR2(100),
constraint DEBTORS_PK PRIMARY KEY (bankruptID));
ALTER TABLE debtors ADD CONSTRAINT debtors_fk0 FOREIGN KEY (category) REFERENCES categories(BankruptCategory);
It has a primary key and a foreign key to another table. Into this table (debtors) I want to import data from a csv file using sqlldr. Here are the ctl and *par *files:
OPTIONS (SKIP=1)
LOAD DATA
CHARACTERSET CL8MSWIN1251
INTO TABLE myschema.debtors
REENABLE DISABLED_CONSTRAINTS EXCEPTIONS EXCEPT_TABLE
FIELDS TERMINATED BY '^'
TRAILING NULLCOLS
(
bankruptID,
category,
lastname,
firstname,
birthdate date 'YYYY-MM-DD HH24:MI:SS',
birthplace
)
userid=username/password@mydb
control=debtors.ctl
log=debtors.log
bad=debtors.bad
data=debtors.csv
direct=true
After completing the task the log file states the following:
Referential Integrity Constraint/Trigger Information: NULL, UNIQUE, and PRIMARY KEY constraints are unaffected.
Constraint mychema.DEBTORS.DEBTORS_FK0 was disabled and novalidated before the load. The following index(es) on table mychema.DEBTORS were processed: index mychema.DEBTORS_PK loaded successfully with 896 keys
Table mychema.DEBTORS has no constraint exception table. No CHECK, REFERENTIAL constraints were re-enabled after the load.
And the foreign key (debtors_fk0) turns disabled. As you can see in the *ctl *file i have the REENABLE clause but it appears not to be working. Could you please help me undestand what the problem is? I want it to reenable the constraint automatically
I created an EXCEPT_TABLE table to store all exceptions, but it didn't help
Everything is as expected. If you checked constraint status, you'd see that it is ENABLED, but NOT VALIDATED - it can't be if there are rows that violate foreign key constraint.
Example 1: what happens when everything is OK?
Sample tables:
Two categories (22, 33) - they will BOTH be used while loading data, which means that foreign key constraint won't be violated:
Control file:
Loading session: with direct path, Oracle automatically disables constraints as described in documentation.
Log file says:
Result:
Example #2: missing foreign key constraint's parent key.
Sample tables:
Category is now missing ID_CAT = 33:
Control file is unmodified - sample data still contains ID_CAT = 33 row.
Nothing changed in a way sqlldr is being called; both rows (even the invalid one!) are loaded:
Log says this (read it carefully!):
Result: both rows in
test(target) table.except_Tablenow contains row which violated foreign key constraint. Constraint status is ENABLED NOT VALIDATED.If you try to manually validate foreign key constraint, you won't be able to do that:
First remove row(s) that violated the constraint, then validate it:
Therefore, yes - everything is OK and works as expected.