Oracle认证辅导:PL/SQL的异常处理
来源:优易学  2011-11-16 16:08:47   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  这样的定义是不能正确处理掉声时所产生的异常。为此必须定义一个封闭块来处理该封闭块的声明部分引发的异常,代码如下 :

  Declare

  V_num number(2) :=100

  Begin

  Null;

  ..

  Exception

  when value_error then

  null;

  when others then

  null;

  End;

  Exception

  when value_error then

  dbms_output.put_line(‘value error occurred’);

  when others then

  dbms_output.put_line(‘…’);

  End;

  这样才能正确的处理声明时的异常

  2、  处理异常部分引发的异常

  只能在异常模块的内部引发 (raise) 外部异常。如:

  Declare

  Excep1 exception;

  Excep2 exception;

  Begin

  Begin

  If  ( 条件 )   then

  Raise excep1;

  End if;

  Exception

  When excep1 then

  Raise excep2;

  End;

  Exception

  When excep2 then

  Null;

  When others then

  Dbms_output.put_line(‘………..’);

  End;

  以上就是关于异常处理的总结,主要的是用户自定义异常这部分比较实用,附上开发规范中的一个例子,备查:

  begin

  select   nvl(bill_id,' ') ,nvl(currency_code,' ')

  into v_receive_id,v_currency_code

  from ar_receivable where ship_no = PI_ship_no;

  exception

  when no_data_found  then --没有找到满足条件记录进行变量的赋值

  v_currency_code := ‘ ‘;            --执行相应的语句

  when dup_val_on_index then      --插入键值重复

  plsql_statements;             --执行相应的语句

  when invalid_number then      --将字符串转换成数据变量期间出错

  plsql_statements  ;

  when too_many_rows then    --返回多个记录到变量中时,出现错误

  plsql_statements;

  when others then              --其他的情况应该如何进行处理

  plsql_statements;

  end;

上一页  [1] [2] [3] [4] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训