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;

猜你喜欢

转载自1124117571.iteye.com/blog/2288667