【问题标题】:ORA-20001, ORA-06512: at line 59 ORA-06512 exception errorORA-20001, ORA-06512: 在第 59 行 ORA-06512 异常错误
【发布时间】:2016-02-14 22:39:42
【问题描述】:

这是我定义异常的 PL/SQL 块的一部分。当我的数据不包含任何异常时它运行正常,但在有异常时会生成错误消息。错误信息如下:“ORA-20001:分数更改无效。 ORA-06512:在第 59 行 ORA-06512: 在第 73 行"

我想知道它出了什么问题。有谁可以帮我离开这里吗?谢谢。

begin

   if (newpoints<0 or newpoints>maximumpoints) then 
            raise invalid_score_change;
         end if; 
exception 
      when invalid_score_change then
         raise_application_error(-20001,'Invalid score change.');
end;

【问题讨论】:

  • 您对编程的实际期望是什么?
  • 这正是你告诉它做的事情。有什么问题?
  • 我在上面简化了我的代码。通常,当 newpoints 小于 0 或大于 maximumpoints 时,我想引发异常错误消息。但它有错误消息 ORA-06512。
  • 它首先有你的 ORA-20001。其余的是异常堆栈,显示它是在哪里引发的。
  • 如果您有一个调用块并且出于某种原因想要隐藏堆栈跟踪,那么the second half of this answer 可能会给出一些指示。我以为我写了一个例子,但找不到。 The article it links to 解释了您所看到的、预期的和通常可取的。如文章所示,报告或存储此类预期异常可能是使用format_error_stack 的正当理由。

标签: oracle exception plsql


【解决方案1】:

尽管正如其他人所建议的那样,该程序正在按照您告诉它的方式执行 - 您的问题是您有一个未绑定的异常,它导致了您想要删除的外部 ORA-06512。您的问题是您在没有处理程序的情况下引发了异常。如果您不想看到 ORA-06512 消息,则需要通过包装另一个异常处理程序来处理这样的异常 - 顺便说一句,我认为这不是好的做法,但我只是在回答您的问题。

begin
    begin

       if (newpoints<0 or newpoints>maximumpoints) then 
            raise invalid_score_change;
       end if; 
     exception 
       when invalid_score_change then
       raise_application_error(-20001,'Invalid score change.');
       --- you are now throwing and unhandled exception to be caught by the next handler below
    end;
 exception
     when others then
       ----- do something
     null; -- just to get it to compile
 end;

【讨论】:

    猜你喜欢
    • 2020-08-23
    • 2020-03-10
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 2016-06-09
    相关资源
    最近更新 更多