在oracle plsql中抑制ORA-06512异常堆栈信息

时间:2013-08-05 12:37:27

标签: oracle plsql plsqldeveloper

我正在为no_data_found使用用户定义的异常,但仍然看到 ORA-06512 堆栈信息与用户定义的异常 ORA-20106

ORA-20106: Problem in loading Affected Circle data
ORA-06512: at "SRUSER.ADD_AFFECTEDCIRCLE", line 30

如何抑制ORA-06512堆栈信息?

这是我的代码

CREATE OR REPLACE FUNCTION get_circleID 
( v_circle_code  vf_circle.circle_code%TYPE)
RETURN vf_circle.circle_id%TYPE
IS
    return_value  vf_circle.circle_id%TYPE; 
BEGIN
    BEGIN
        SELECT circle_id INTO return_value
        FROM vf_circle
        WHERE circle_code = v_circle_code;
   END;
   RETURN return_value;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20102, 'Circle Code is wrong or not available',TRUE);
END get_circleID;
/

2 个答案:

答案 0 :(得分:2)

我觉得有人在错误/异常处理中请求更少的信息有点奇怪。我通常尽可能多地堆积堆栈跟踪(更多的是更好!)。但也许你在有正当理由的环境中工作。

你在找这样的例子吗?

-- exception types and related error codes encapsulated 
-- into an application specific package
create or replace package expkg is
  dummy_not_found constant number := -20102;
  dummy_not_found_ex exception;
  -- numeric literal required
  pragma exception_init (dummy_not_found_ex, -20102);
  -- helper to hide a bit esoteric string handling
  -- call only in exception handler !
  function get_exception_text return varchar2;
end;
/

create or replace package body expkg is
  function get_exception_text return varchar2 is
  begin
    -- returns only the first line of a multiline string
    return regexp_substr(sqlerrm, '^.+$', 1, 1, 'm');
  end;
end;
/

begin
  declare
    v_dummy dual.dummy%type;
  begin
    select dummy into v_dummy from dual where dummy = 'A';
  exception
    -- convert exception type
    when no_data_found then
      raise_application_error(expkg.dummy_not_found, 'Not A dummy !', true);
  end;
exception
  when expkg.dummy_not_found_ex then
    -- DIY if the default format doesn't fit 
    dbms_output.put_line(expkg.get_exception_text);
end;
/

<强>输出:

ORA-20102: Not A dummy !

答案 1 :(得分:1)

我认为您需要定义Pragma异常init来定义用户定义的消息和错误号。如下所示

    pragma exception_init( Message, Number );