PL/SQL程序之例外
来源:互联网 发布:金属中性笔 知乎 编辑:程序博客网 时间:2024/06/05 23:08
什么是例外?例外是程序设计语言提供的一种功能,用来增强程序的健壮性和容错性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 …例二:用户自定义例外declarecursor c1(emp_no number) is select * from emp where empno=emp_no;emprow emp%rowtype;no_found exception;beginopen c1(1000);fetch c1 into emprow;if c1%notfound then raise no_found;end if;close c1;exceptionwhen no_found thendbms_output.put_line('用户自定义的例外');end;