异常处理+异常+处理异常+自定义异常

异常
1PL/SQL程序块在执行中出现的错误
2程序产生异常,如果没有处理语句,程序停止执行.
3异常的类型
1)预定义异常
2)非预定义异常
3)自定义异常

处理异常
exception
when exception1 then statements1;
when exception2 then statements2;
【…】
when others then statementN;
exception :表示出现的异常名称
when others:表示任何其他异常,类似else,该字句要放到最后

自定义异常
1用户自己在PL/SQL程序块,子程序或包中定义异常
2自定义异常需要在PL/SQL程序块的声明部分中进行声明
3oracle允许使用pragma关键字,让异常名和异常号连接起来.
4.用户自定义异常需要使用raise语句显示触发,也就是
raise exception_name,然后进行异常处理。
语法
exception_name exception
pragma exception_init(exception_name ,exception_no)

异常举例

declare

e_noDate_studemt exception;–自定义异常
pragma exception_init(e_noDate_studemt ,-1101);–让异常名和异常号连接起来

begin
update student set sname=’lihua’ where sno=’s01’;
IF SQL%notfound then –如果没有数据
raise e_noDate_studemt;–抛出异常
end if;
exception –异常处理
when e_noDate_studemt then
dbms_output.put_line(‘没有s01编号的学生’);
end;

这里写图片描述

转载于:https://www.cnblogs.com/feiZhou/p/9344329.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值