java.sql.SQLException: ORA-02291: integrity constraint violated - par

本文详细解析了ORA-02291错误的原因及解决方案,该错误通常出现在尝试插入不存在父记录的子记录时。文章指导如何通过添加父记录或删除外键来解决问题,并介绍了主键和外键的概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java.sql.SQLException: ORA-02291: integrity constraint (BOOKER.FK_ANDON_EVENT_STATUS) violated - parent key not found

 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
        at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
        at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
        at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
        at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)

原因:http://www.dba-oracle.com/t_ora_02291_integrity_constraint_string_string_violated_parent_key_not_found.htm

The Oracle docs note this on the ora-02291 error:

 ORA-02291: integrity constraint (string.string) 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.

For an insert statement, this ORA-02291 error is common when you are trying to insert a child without a matching parent, as defined by a foreign key constraint.  In that case, you need to add the parent row to the table and then re-insert your child table row.

See the dba_constraints view to find the parent table.

To fully understand [primary and foreign key constraints, see the book Easy Oracle Jumpstart, to explain these concepts:


实体完整性错误
你的外键FK_ANDON_EVENT_STATUS中对应的父表的列中没有相关数据就会出这错,应该先插入父表,再插子表

表a有一外键,指向表b,那么b就是a的parent table,外键所指的列就是parent key


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值