PL/SQL程序之例外

什么是例外?
例外是程序设计语言提供的一种功能,用来增强程序的健壮性和容错性
Oracle的异常处理
系统定义例外
No_data_found    (没有找到数据)
Too_many_rows          (select …into语句匹配多个行) 
Zero_Divide   ( 被零除)
Value_error     (算术或转换错误)
Timeout_on_resource      (在等待资源时发生超时)

例一:除0例外
SQL> declare
  2  pnum number :=10;
  3  begin
  4  pnum :=pnum/0;
  5  exception
  6  when zero_divide then 
  7  dbms_output.put_line('除0啦');
  8  end;
  9  /
 
除0啦

用户定义例外及处理例外
在declare节中定义例外   
out_of   exception ;
在可行语句中引起例外  
raise out_of ;
在Exception节处理例外
when Out_of then …

例二:用户自定义例外
declare
cursor c1(emp_no number) is select * from emp where empno=emp_no;
emprow emp%rowtype;
no_found exception;
begin
open c1(1000);
fetch c1 into emprow;
if c1%notfound then raise no_found;
end if;
close c1;
exception
when no_found then
dbms_output.put_line('用户自定义的例外');
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值