系统exception,以及自定义例外

来源:互联网 发布:软件总工程师简历 编辑:程序博客网 时间:2024/05/16 09:06

/*
Zero_Divide ( 被零除)

*/
set serveroutput on
declare
pnum number;
begin

pnum := 1/0;

exception
when Zero_Divide then dbms_output.put_line(‘1: 0不能做被除数’);
dbms_output.put_line(‘2: 0不能做被除数’);
when Value_error then dbms_output.put_line(‘算术错’);
when others then dbms_output.put_line(‘其他例外’);
end;
/

–自定义例外: 查询50号部门的员工姓名

set serveroutput on

declare
cursor cemp is select ename from emp where deptno=50;
pename emp.ename%type;

–自定义例外
no_emp_found exception;
begin
open cemp;
–取一个员工
fetch cemp into pename;
if cemp%notfound then
raise no_emp_found;
end if;

/*
if cemp%isopen then
close no_emp_found;
end if;
*/
close cemp;

exception
when no_emp_found then dbms_output.put_line(‘没有找到员工’);
when others then dbms_output.put_line(‘其他例外’);

end;
/

0 0
原创粉丝点击