如何在PL/SQL块中捕获唯一约束错误? [英] How to catch a unique constraint error in a PL/SQL block?

查看:117
本文介绍了如何在PL/SQL块中捕获唯一约束错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个Oracle PL/SQL块,它将记录插入表中,并且需要从唯一约束错误中恢复,就像这样:

Say I have an Oracle PL/SQL block that inserts a record into a table and need to recover from a unique constraint error, like this:

begin
    insert into some_table ('some', 'values');
exception
    when ...
        update some_table set value = 'values' where key = 'some';
end;

是否可以用省略号代替某些东西以捕获唯一的约束错误?

Is it possible to replace the ellipsis for something in order to catch an unique constraint error?

推荐答案

EXCEPTION
      WHEN DUP_VAL_ON_INDEX
      THEN
         UPDATE

这篇关于如何在PL/SQL块中捕获唯一约束错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆