如何继续超出异常的PL / SQL执行?

时间:2015-07-16 16:37:37

标签: oracle plsql exception-handling oracle11g

exceptions processing article表示推杆 嵌套块中的EXCEPTIONS子句。 当异常发生时,继续下一条记录。

它适用于此OP

但是,当我尝试这个时,我得到PLS-000103 Error

这是我的代码:

问题

如何继续处理非例外记录(A,C,E)?

set serveroutput on;
/* Goal is to process all records that don't cause exceptions.
Using guidance from 
http://www.oracle.com/technetwork/issue-archive/2011/11-mar/o29plsql-085126.html
Desired results
===============
A
C
E
*/

declare
  v_exception varchar2(1);
  v_item_a    varchar2(2);
  v_item_b    varchar2(1);

  cursor c_list
  is 
  (
  select 'A'  as item from dual union all
  select 'BB' as item from dual union all
  select 'C' as item from dual union all
  select 'DD' as item from dual union all
  select 'E' as item from dual union all
  select 'FF' as item from dual);

begin

  for items in c_list loop
     v_item_b := items.item;
     dbms_output.put_line(v_item_b);
     /* Putting an excpetion block inside the for loop causes
        PLS-00103: Encountered the symbol "EXCEPTION" 

       exception when others
       then dbms_output.put_line('Msg 28:[' || SQLERRM || ']');
       end;
      */ 
  end loop;
     /* Putting it here works.         
     */
  exception when others
  then dbms_output.put_line('Exception OK here:[' || SQLERRM || ']');
  end;

1 个答案:

答案 0 :(得分:1)

尝试阻止(并且通常避免其他人)

BEGIN
   <the statement that can raise the exception>
EXCEPTION
   WHEN OTHERS THEN
      ...
END;