oracle(7)例外处理
oracle将例外分为预定义例外,非预定义例外和自定义例外三种
预定义例外用于处理常见的oracle错误
非预定义例外用于处理预定义例外不能处理的例外
自定义例外用于处理与oracle错误无关的其它情况
案例(预定义例外) 编写一个过程,可接收雇员的编号,并显示该雇员的姓名(如果编号不存在,怎么处理) www.2cto.com
declare
–定义
v_ename emp.ename%type;
begin
—
select ename into v_ename from emp where empno=&gno;
dbms_output.put_line('名字:'||v_ename);
exception
where no_data_found then
dbms_output.put_line('编号不存在!');
end;
案例(自定义例外) 在表更新中 当输入的编号不存在 oracle不报错 需要自己定义例外
create or replace procedure ex_oracle账号text(spNo number)
is www.2cto.com
–定义一个例外
myex exception;
begin
–更新用户sal
update emp set sal=sal+1000 where empno=spNo;
–sql%notfound这是表示没有update
–raise myex 触发myex
if sql%notfound then
raise myex;
end if;
exception
when myex then
dbms_output.put_line('没有更新任何用户');
end;
作者 kyle8525_nsn