简体   繁体   English

即使在PL / SQL中发生异常,也继续循环读取Excel行

[英]Continue loop in reading excel rows even when an exception occurred in PL/SQL

Here's the overview of the code: 以下是代码概述:

PROCEDURE

BEGIN
  WHILE LOOP --loop each row
    --Read each row and add in table
    COMMIT;
  END LOOP;
EXCEPTION
  WHEN OTHERS
    --log error
    ROLLBACK;
END;

Ex: There are 5 lines. 例如:有5行。 The 3rd line has an error in it. 第三行中有错误。 The program stops right after it reads the error line, making the other lines next to it not evaluated/read. 程序在读取错误行后立即停止,使它旁边的其他行不被评估/读取。 My goal is after it went to the exception, it will output the line and continue with reading the other lines. 我的目标是转到异常之后,它将输出该行并继续读取其他行。 So how do I return back to the loop if it went to the exception? 那么,如果发生异常,如何返回到循环呢?

Try this, then you will cache error only in inner anonymous block: 试试这个,那么您将只在内部匿名块中缓存错误:

PROCEDURE

BEGIN
  WHILE LOOP --loop each row
    BEGIN
      --Read each row and add in table
      COMMIT;
    EXCEPTION
      WHEN OTHERS
        --log error
        ROLLBACK;
    END;
  END LOOP;

END;

Try using a independent PL/SQL block in the loop itself. 尝试在循环本身中使用独立的PL / SQL块。

BEGIN
      WHILE LOOP --loop each row
        BEGIN
        --Read each row and add in table
        COMMIT;
            EXCEPTION --Catch the exception here and print the data and it will move on
        END;
      END LOOP;
    EXCEPTION
      WHEN OTHERS
        --log error
        ROLLBACK;
    END;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM