我有这样的代码:
try {
insertRowInDatabase();
} catch(SQLIntegrityConstraintViolationException e) {
//row already inserted. Do nothing.
} catch(Exception other) {
//we should retry to insert row
retry();
} 有没有可能,在oracle数据库中插入行会抛出SQLIntegrityConstraintViolationException,但数据库中终究不会出现该行。
发布于 2018-08-13 23:44:16
有可能吗?好的。如果有一个外键约束,或者表上有一个自定义触发器来阻止插入,该怎么办呢?如果没有模式,就很难判断。
发布于 2018-08-13 23:47:36
据我所知,您需要PL/SQL语言的MERGE,它类似于mysql的ON DUPLICATE KEY UPDATE...
您可以查看MERGE示例here
https://stackoverflow.com/questions/51826004
复制相似问题