How do you query an 11g Oracle database to get a description of an error code?
Anonymous : I want to write a procedure which will return the description of an error code I give to it. So when it's written I could call it like this:
select ora_code_desc('ORA-00000')
from dual;
And it would output:
Normal, successful completion.
Cause: An operation has completed normally, having met no exceptions.
Action: No action required.
Solution :
It's not accessible from SQL but within PL/SQL, you can use the SQLERRM function.
For example
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.
You could, of course, build an ora_code_desc function that took in a string, removed the first three characters, passed the resulting number to SQLERRM, and returned the result
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
Oracle also ships a utility on Unix platforms oerr that provides more detail-- particularly the cause and action you're looking for. If you really want that data too, you could write a Java stored procedure that called out to an operating system shell, executed an oerr command, and returned the result. That would give you more data but would, obviously, be much more complex.
Source :
http://stackoverflow.com/questions/11892043/query-oracle-for-ora-code-error-details
Cheers!
No comments:
Post a Comment