Oracle9i异常处理分为系统预定义异常处理和自定义异常处理两部分。
自定义异常处理
1.定义异常处理
declare 异常名 exception;
2.触发异常处理
raise 异常名
3.处理异常
exception
when 异常名1 then
异常处理语句段1;
when 异常名2 then
异常处理语句段2;
示例:
set serveroutput on
declare
salaryerror exception;
tempsal scott.emp.sal%type;
begin
select sal into tempsal
from scott.emp
where empno=7566;
if tempsal<900 or tempsal>2600 then
raise salaryerror;
end if;
exception
when salaryerror then
dbms_output.put_line('薪水超出范围');
end;