• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql
You are here: Home / Oracle / function / SQLERRM Function in Oracle SQL – PLSQL

SQLERRM Function in Oracle SQL – PLSQL

November 21, 2012 by techhoneyadmin

The SQLERRM Function in Oracle SQL / PLSQL is used to get the error message related with the latest generated exception.
The SQLERRM function should be used in the exception handling segment of the code.

A typical exception handling portion of code may look like;

EXCEPTION
WHEN exception_name1 THEN
[Statements / business logic]

WHEN exception_name2 THEN
[Statements / business logic]

WHEN exception_name3 THEN
[Statements / business logic]
.
.
WHEN exception_nameN THEN
[Statements / business logic]
END [procedure_name];

We can use the SQLERRM function to raise an error / exception as shown below.

view source
print?
1EXCEPTION
2WHEN OTHERS THEN
3raise_application_error(-1001,'An error occurred: ' || SQLCODE || ' ERROR NUMBER:-' ||SQLERRM);
4END;

We can also insert the error / exception in a database table as shown below:

view source
print?
1EXCEPTION
2WHEN OTHERS THEN
3  error_code := SQLCODE;
4  error_message  := substr(SQLERRM,1,300);
5INSERT INTO error_table(error_num, error_msg)
6VALUES(error_number, error_message);
7END;

Filed Under: function Tagged With: how to use SQLERRM function in oracle database query, how to use SQLERRM function in oracle plsql, how to use SQLERRM function in oracle sql, SQLERRM function in oracle plsql, SQLERRM function in oracle sql, SQLERRMPLSQL, syntax and example of SQLERRM function in oracle plsql, syntax and example of SQLERRM function in oracle sql, using SQLERRM function in oracle database query, using SQLERRM function in oracle plsql, using SQLERRM function in oracle sql

Copyright © 2025 · Parallax Pro on Genesis Framework · WordPress · Log in