【问题标题】:How to continue PL/SQL excution beyond exceptions?如何在异常之外继续执行 PL/SQL?
【发布时间】:2015-10-06 05:37:27
【问题描述】:

这个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;

【问题讨论】:

    标签: oracle plsql exception-handling oracle11g


    【解决方案1】:

    尝试一个块(通常避免 WHEN OTHERS)

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

    【讨论】:

    • 那行得通。通过在 for 循环后添加 begin 可以按预期处理异常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多