Oracle存储过程中自定义异常存储过程中自定义异常
ORACLE 用户自定义异常小例子
1.进入pl/sql测试窗口
2.执行语句
declare
empname varchar2(255);
customize_exp EXCEPTION; –自定义异常
begin
FOR c IN (select d.* from scott.dept d) LOOP
begin
dbms_output.put_line('dept: ' || c.deptno || '=' || c.dname);
–当部门ID为40时抛出异常
if (c.deptno = 40) then
RAISE customize_exp; — 抛出自定义异常
end if;
–当部门ID为10、20、30时,会执行下面的查询,由于出现多行所以会报 Too many rows round!
–当部门ID为40时,这里不再执行,控制转向
select e.ename into empname from scott.emp e
where e.deptno = c.deptno;
exception
when customize_exp then
dbms_output.put_line('customize error!');
when no_data_found then
dbms_output.put_line('Data is not found!');
when too_many_rows then
dbms_output.put_line('Too many rows round!');
when OTHERS then
dbms_output.put_line('others error');
end;
END LOOP;
end;
3.结果
评论0