Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parent key not found thought it is there

MWshobzJun 12 2015 — edited Jun 15 2015

Hi Oracle Gurus,

I have Parent and child table with a Primary key and Foreign Key constraint established.

I have 2 insert statement

INSERT INTO INVOICE ( INVOICE_GID,       INVOICE_XID,       INVOICE_TYPE,       INVOICE_SOURCE, INVOICE_DATE,       DATE_RECEIVED,......)

INSERT INTO INVOICE_STATUS(INVOICE_GID,STATUS_TYPE_GID,STATUS_VALUE_GID, DOMAIN_NAME,INSERT_USER, INSERT_DATE)...

First statement inserts into the Parent and the next into Child. I get the below error randomly.

Error report -

ORA-02291: integrity constraint (GLOGOWNER.FK_INV_STU_INV_GID) violated - parent key not found

ORA-06512: at "APL_GLOGEXTN.APLL_CE_MANAGEMENT", line 1774

ORA-06512: at line 14

02291. 00000 - "integrity constraint (%s.%s) violated - parent key not found"

*Cause:    A foreign key value has no matching primary key value.

*Action:   Delete the foreign key or add a matching primary key.

1. I have used the same INVOICE_GID for both child and parent and confirmed that  the ID is available.. The values are not NULL as well..

2. I also issued a commit after Parent table insert, still the error occurs..

3. If I issue a WAIT command or after few second, do the Child table insert, then child record gets inserted.

4. I also tried to issue a ALTER SESSION SET CONSTRAINTS= IMMEDIATE, and then run the insert. Still it does not work..

The integrity constraint is NOT DEFERRABLE IMMEDIATE.

Same piece of code works  some time.

Why is this random behavior? Any idea or anything that I should take care off.

Regards,

Shobana

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2015
Added on Jun 12 2015
5 comments
1,653 views