Skip to Main Content

Oracle Database Discussions

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!

ORA-02291: integrity constraint violated - parent key not

436502Jul 16 2007 — edited Jul 30 2007
Hi,
I am running following INSERT and getting parent key not found error.
ERROR at line 1:
ORA-02291: integrity constraint (O_ITEM_REL_FK1) violated - parent key not found

o_item (parent) and o_item_REL (child) has parent child relationship.
Both id i am generating through sequence and I have to load id values in both table same time means when i generate sequence in o_item table then same value i have to load in o_item_REL table. It was running fine and suddenly it's throwing this error.
My where clause running fine and without child table insert it's also running fine. (see in bold)

SQL
INSERT ALL
INTO o_item
(o_item_id, PROD_ID, PRICE, L_Total, Q_ORDER, Q_SHIP, L_NUM
)
VALUES
('LD_'||o_item_seq.NEXTVAL, PRODUCT_ID, PRICE, L_Total, Q_ORDER, Q_SHIP, L_NUM
)
INTO o_item_REL
(O_ID,
o_item_id
)
VALUES (o_id,
'LD_'||o_item_seq.CURRVAL
)
SELECT A.PROD_ID, D.O_id, A.PRICE, A.L_Total, A.Q_ORDER, A.Q_SHIP, A.L_NUM
FROM o_load A,
O_item C,
o_item_REL B,
ord D
WHERE A.prod_id = C.prod_id
AND A.j_ref_num = C.n_ord_id
AND A.n_ord_id = D.n_ord_id
AND C.o_item_id = B.o_item_id
AND (A.N_ORD_ID not in (select F.n_ord_id from o_item F
where F.n_ord_id = a.n_ord_id
)
OR (A.N_ORD_ID in (select F.n_ord_id from o_item F
where F.n_ord_id = a.n_ord_id
)
AND A.prod_id not in (select F.prod_id from o_item F
where F.n_ord_id = a.n_ord_id
)
)
)
/
commit;

Please let me know, appreciated.

Thanks,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2007
Added on Jul 16 2007
11 comments
1,375 views