加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL自定义异常

发布时间:2020-12-13 17:14:53 所属栏目:百科 来源:网络整理
导读:在Oracle的procedure里,我们会用for update nowait锁一些记录,防止多个用户同时修改同一条记录。为了捕捉ora-00054错误,并对用户进行友好提示,开发人员自定义了一个exception,叫RESOURCE_BUSY_EXCEPTION,关联的Oracle错误代码就是ora-00054。这个自定

  在Oracle的procedure里,我们会用for update nowait锁一些记录,防止多个用户同时修改同一条记录。为了捕捉ora-00054错误,并对用户进行友好提示,开发人员自定义了一个exception,叫RESOURCE_BUSY_EXCEPTION,关联的Oracle错误代码就是ora-00054。这个自定义的exception在EDB里报错。

  原因是EDB里的自定义异常,只能绑定-20000 and -20999之间的错误代码。

  在PG中,捕获未获得行锁的异常处理的例子:

1.通过错误码捕获

do $$declare
errmsg text;
begin
select * from t1 for update nowait;
exception
when SQLSTATE '55P03' then
raise INFO 'row locked by others';
when others then
raise INFO 'others error';
end$$;

2.通过异常名捕获

do $$declare
errmsg text;
begin
select * from t1 for update nowait;
exception
whenlock_not_available then
raise INFO 'row locked by others';
when others then
raise INFO 'others error';
end$$;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读