SQLIntegrityConstraintViolationException

时间:2018-08-13 15:39:46

标签: java sql jdbc oracle11g

我有此代码:

try {
   insertRowInDatabase();
} catch(SQLIntegrityConstraintViolationException e) {
  //row already inserted. Do nothing.
} catch(Exception other) {
  //we should retry to insert row
  retry();  
} 

是否有可能在Oracle数据库中插入行会引发SQLIntegrityConstraintViolationException,但是数据库中最终将没有该行。

2 个答案:

答案 0 :(得分:0)

有可能吗?当然。如果存在外键约束或表上的自定义触发器会阻止插入怎么办?没有模式,很难说。

答案 1 :(得分:0)

据我了解,您需要PL / SQL的MERGE,类似于mysql的ON DUPLICATE KEY UPDATE...

您可以看到MERGE示例here

相关问题