首页 > 解决方案 > SQLIntegrityConstraintViolationException

问题描述

我有这个代码:

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

是否有可能,将行插入 oracle 数据库会引发 SQLIntegrityConstraintViolationException,但该行毕竟在数据库中不存在。

标签: javasqljdbcoracle11g

解决方案


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

你可以在这里看到MERGE例子


推荐阅读