【问题标题】:how to catch error in procedure that was raised inside other procedure , oracle SQL 10g如何捕获在其他过程中引发的过程中的错误,oracle SQL 10g
【发布时间】:2014-05-12 13:26:19
【问题描述】:

我有 other_procedure 可以做一个

RAISE_APPLICATION_ERROR(-20001,'Some text here');

当发生错误时,我想跳到循环的末尾,我这样做了。但我不知道如何发现这个错误。

请注意,我使用的是 Oracle 10g,所以我无法使用 continue,这就是我使用 GOTO 的原因。

我试过了,但有异常无法编译。

create or replace procedure my_procedure
as    
begin
  for item
  IN some_cursor
  LOOP
    if(condition) then
      other_procedure; 
      exception when -20001 then
            goto end_loop;
      --some code here 
    end if;
    <<end_loop>>
    null; 
  END LOOP;
end;

【问题讨论】:

  • 好的,因为downvoters,我选择完全重新制作它,现在过程将IN OUT参数传递到嵌套过程中,在我曾经引发错误的地方设置为0或1

标签: sql oracle stored-procedures plsql


【解决方案1】:

如果您尝试处理自定义错误,则必须使用 PRAGMA EXCEPTION_INIT 将其绑定到异常。

另外需要注意的是,您附加的异常是针对您的主过程 my_procedure,编译错误是因为 IF/LOOP 仍未在主体中关闭,因为异常表示异常处理程序的开始

它应该是这样的

CREATE OR REPLACE PROCEDURE my_procedure
AS
   custom_exception   EXCEPTION;
   PRAGMA EXCEPTION_INIT (custom_exception, -20001); -- bind error code to custom_exception
BEGIN
   FOR item IN some_cursor
   LOOP
      IF (condition)
      THEN
         BEGIN
            other_procedure;
         EXCEPTION
            WHEN custom_exception -- handle error from other_procedure
            THEN
               GOTO end_loop;
         END;                                                 
      --some code here
      END IF;

     <<end_loop>>
      NULL;
   END LOOP;
END;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多