查询Oracle以获取ORA代码错误详细信息

ken*_*dds 3 sql oracle error-handling

我的问题:如何查询11g Oracle数据库以获取错误代码的描述?

背景:有人告诉我他们曾经看过代码,它会查询oracle以获取有关特定ORA-code错误的详细信息.我一直在Google上搜索一段时间,似乎无法找到类似的东西.有谁知道这是否可能?对它有什么看法吗?

原因:我想写一个程序,它将返回我给它的错误代码的描述.所以当它写完时我可以这样称呼它:

select ora_code_desc('ORA-00000')
from dual;
Run Code Online (Sandbox Code Playgroud)

它会输出:

Normal, successful completion.
Cause: An operation has completed normally, having met no exceptions.
Action: No action required.
Run Code Online (Sandbox Code Playgroud)

或类似的东西:)谢谢你的帮助!

Jus*_*ave 8

它不能从SQL访问,但在PL/SQL中,您可以使用该SQLERRM函数.

例如

SQL> ed
Wrote file afiedt.buf

  1  begin
  2    dbms_output.put_line( sqlerrm(0) );
  3    dbms_output.put_line( sqlerrm(-1041) );
  4* end;
SQL> /
ORA-0000: normal, successful completion
ORA-01041: internal error. hostdef extension doesn't exist

PL/SQL procedure successfully completed.
Run Code Online (Sandbox Code Playgroud)

当然,您可以构建一个ora_code_desc函数,该函数接受一个字符串,删除前三个字符,将结果数传递给SQLERRM,并返回结果

SQL> ed
Wrote file afiedt.buf

  1  create or replace function ora_code_desc( p_code in varchar2 )
  2    return varchar2
  3  is
  4    l_str varchar2(1000);
  5  begin
  6    l_str := sqlerrm( substr(p_code, 4 ) );
  7    return l_str;
  8* end;
SQL> /

Function created.

SQL> select ora_code_desc( 'ORA-00000' ) from dual;

ORA_CODE_DESC('ORA-00000')
--------------------------------------------------------------------------------
ORA-0000: normal, successful completion
Run Code Online (Sandbox Code Playgroud)

Oracle还船舶在Unix平台上的实用程序OERR提供特别的原因,并采取行动,你正在寻找更多的detail--.如果您确实也想要这些数据,那么您可以编写一个Java存储过程,该存储过程调用操作系统shell,执行oerr命令并返回结果.这会给你更多的数据,但显然会更复杂.