Pages

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