Skip to main content

SQLCODE & SQLERRM Function



The SQLCODE function returns the error number associated with the most recently raised error exception. This function should only be used within the Exception Handling section of your code.

The SQLERRM function returns the error message associated with the most recently raised error exception. This function should only be used within the Exception Handling section of your code.
You could use the SQLCODE & SQLERRM  function to raise an error as follows:
EXCEPTION
   WHEN OTHERS THEN
      raise_application_error(-20001,'Error - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
Or you could log the error to a table using the SQLCODE & SQLERRM function as follows:
EXCEPTION
   WHEN OTHERS THEN
      ERR_CODE := SQLCODE;
      ERR_MSG := SUBSTR(SQLERRM, 1, 200);

      INSERT INTO XXERROR_TABLE (ERROR_CODE, ERROR_MSG)
      VALUES (ERR_CODE, ERR_MSG);
END;

Comments