PostgreSQL自定义异常

news/2024/7/9 22:51:53 标签: PostgreSQL, 数据库

  在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$$;

http://www.niftyadmin.cn/n/1317683.html

相关文章

漏洞扫描

漏洞扫描 漏洞扫描器是一种能够自动在计算机,信息系统、网络及应用软件中寻找和发现安全弱点的程序。 它通过网络对目标系统进行探测,向目标系统发生数据,并将反馈数据与自带的漏洞特征进行匹配,进而列举目标系统上存在的安全漏…

14_THINKPHP链式查询-field

<?phpnamespace app\controller;use think\Db;class LinkField {public function index(){//field//字符串//$result Db::name(user)->field(userid,username)->select();//数组 // $result Db::name(user) // ->field([username,userid,age])-…

angular.copy实例

test.html <html> <head><title>angular.copy实例</title> </head> <body><h1>angular.copy实例</h1><div ng-controller"Controller"><form>Name: <input type"text" ng-model"user…

HLA高层体系结构+RTI(2)

HLA按照面向对象的思想和方法来构建仿真系统&#xff0c;在面向对象分析与设计的基础上划分仿真成员&#xff0c;构建仿真联邦的技术。 联邦federation&#xff1a;用于达到某一特定仿真目的的分布仿真系统&#xff0c;由若干个相互作用的联邦成员构成。最典型的联邦成员是仿真…

15_THINKPHP链式查询//限制,分页,排序,分组,分组筛选

<?phpnamespace app\controller;use think\Db;class LinkGroup {public function index(){//限制&#xff0c;分页&#xff0c;排序&#xff0c;分组&#xff0c;分组筛选//限制limit // $result Db::name(user) // ->limit(3) // ->s…

网络安全测试工程师职能

网络安全测试工程师职能 风控部门【信息安全专业】>>>>>【信息安全】 网络安全测试 任职具备技能 岗位职责&#xff1a;>>> 【1】负责为客户的IT基础设施和应用系统&#xff08;Web类和移动应用类&#xff09;完成漏洞扫描、渗透测试服务。【2】协助…

获取焦点ng-focus实例

test.html <html> <head><title>获取焦点ng-focus实例</title> </head> <body ng-controller"Controller"><h1>获取焦点ng-focus实例</h1><div>演示实例&#xff1a;你可以点击获取焦点&#xff0c;当前焦点在…

github回滚到某个commit记录

首先在本地仓库文件夹内右键选择git bash here 进入MINGW64的git bash窗口&#xff0c; 输入git log&#xff0c;查看commit history 找到要恢复的那条commit 记录下commit后面那条数字&#xff0c;表示唯一id标识 输入git reset --hard 02197356d1e9dfa2f150dfc03b36a24354…