15.预定义例外1

处理预定义例外


预定义例外是由pl/sql所提供的系统例外。当pl/sql应用程序违反了oracle规定的限制时,则会隐含的触发一个内部例外。

pl/sql为开发人员提供了二十多个预定义例外

常用的例外
1.case_not_found:
在开发pl/sql块中编写case语句时,如果在when子句中没有包含必须的条件分支,就会触发case_not_found的例外。

实例:
create or replace procedure sun_pro15(sunNo number) is
v_sal emp.sal%type;
begin
select sal into v_sal from emp where empno=sunNo;
case
when v_sal<1000 then
update emp set sal=sal+100 where empno=sunNo;
when v_sal<2000 then
update emp set sal=sal+200 where empno=sunNo;
end case;
exception
when case_not_found then
dbms_output.put_line('case语句没有与'||v_sal||'相匹配的条件');
end;



2.cursor_already_open
当重新打开已经打开的游标时,会隐含的触发例外cursor_already_open

实例:
declare
cursor emp_cursor is select ename,sal from emp;
begin
open emp_cursor;
for emp_recordl is emp_cursor loop
dbms_output.put_line(emp_recordl.ename);
end loop;
exception
when cursor_already_open then
dbms_output.put_line('游标已经打开');
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值