Pages

OracleEBSpro is purely for knowledge sharing and learning purpose, with the main focus on Oracle E-Business Suite Product and other related Oracle Technologies.

I'm NOT responsible for any damages in whatever form caused by the usage of the content of this blog.

I share my Oracle knowledge through this blog. All my posts in this blog are based on my experience, reading oracle websites, books, forums and other blogs. I invite people to read and suggest ways to improve this blog.


Wednesday, February 20, 2013

SQLERRM


Definition:
In Oracle PL/SQL, SQLERRM is an error trapping function which returns the predefined error message corresponding to the input error number argument. If no argument has been provided, SQLERRM returns the error message associated with the last standard exception raised by the Oracle Server. It is defined in the Oracle STANDARD package.

For user defined exceptions, SQLERRM returns the error message defined for an error number in PRAGMA EXCEPTION_INIT.

If SQLERRM is invoked in the execution portion of the block, it returns "ORA-0000: normal, successful completion".

Example Syntax:
SQLERRM(Error Number)


Example Usage:

The PL/SQL block below raises ZERO_DIVIDE exception and displays the error message corresponding to error number-01476.

DECLARE

  L_NUM1 NUMBER;

  L_NUM2 NUMBER;

BEGIN

  L_NUM1 := 10;

  L_NUM2 := 0;

  DBMS_OUTPUT.PUT_LINE('RESULT:'||L_NUM1/L_NUM2);

EXCEPTION

  WHEN OTHERS THEN

     DBMS_OUTPUT.PUT_LINE('Exception Message:'||SQLERRM);

END;

/



Exception Message:ORA-01476: divisor is equal to zero



PL/SQL procedure successfully completed.

No comments:

Post a Comment