什么是例外?
例外是程序设计语言提供的一种功能,用来增强程序的健壮性和容错性
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;
PL/SQL程序之例外
最新推荐文章于 2024-10-18 17:33:55 发布