java - SQLIntegrityConstraintViolationException
问题描述
我有这个代码:
try {
insertRowInDatabase();
} catch(SQLIntegrityConstraintViolationException e) {
//row already inserted. Do nothing.
} catch(Exception other) {
//we should retry to insert row
retry();
}
是否有可能,将行插入 oracle 数据库会引发 SQLIntegrityConstraintViolationException,但该行毕竟在数据库中不存在。
解决方案
据我了解,您需要 PL/SQL 的MERGE
,它类似于 mysql 的ON DUPLICATE KEY UPDATE...
你可以在这里看到MERGE
例子
推荐阅读
- linux - linux合并多个文件,但跳过以'#'开头的行
- mysql - 为什么 MySQL 在查询结果的末尾添加不必要的填充?
- android - 在 Fragment 页面底部截断项目
- c++ - QStringList.size 返回两个值
- javascript - NetSuite:TypeError:log.debug 不是客户端脚本中的函数(SuiteScript 2.0)
- dask - Distributed.scheduler.KilledWorker 异常的根本原因是什么?
- ios - 带有约束的 Swift UITextView 不可见
- symfony-4.3 - 路由 symfony4 中的 NotFoundHttpException
- android - 使用合并标签时复合视图不可见
- ruby - 查找具有相同数字的下一个最小数字