自定义oracle异常,Oracle自定义异常

--抛出异常的用法

declare

type emps_record_type is record

(

emps_id emps.id%type,

age emps.age%type,

name emps.name%type,

sal emps.sal%type

);

emps_record emps_record_type;

cursor emps_cursor is select * from emps;

love exception;

loves exception;

begin

update emps set sal = 1111111 where id = 1;

if SQL%notfound then

raise_application_error(-20010,'user error');--抛出异常,声明了错误代码

end if;

exception when others then

dbms_output.put_line('Some Happened ! '||sqlerrm);--sqlerrm为oracle的错误代码还有sqlcode

end;

declare

type emps_record_type is record

(

emps_id emps.id%type,

age emps.age%type,

name emps.name%type,

sal emps.sal%type

);

emps_record emps_record_type;

cursor emps_cursor is select * from emps;

--定义两个异常变量

love exception;

loves exception;

begin

update emps set sal = 1111111 where id = 1;

--插入不成功异常

if SQL%notfound then

--抛出异常用raise

raise love;--直接抛出,没有任何声明

end if;

exception when love then --捕获异常

dbms_output.put_line('love');

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值