• 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 / SQLCODE Function in Oracle SQL – PLSQL

SQLCODE Function in Oracle SQL – PLSQL

November 21, 2012 by techhoneyadmin

The SQLCODE Function in Oracle SQL / PLSQL is used to get the error number related with the latest generated exception.
The SQLCODE 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 SQLCODE function to raise an error / exception as shown below.

EXCEPTION
WHEN OTHERS THEN
raise_application_error(-1001,'An error occurred: ' || SQLCODE || ' ERROR NUMBER:-' ||SQLERRM);
END;

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

 EXCEPTION
WHEN OTHERS THEN
  Error_code := SQLCODE;
  Error_message  := substr(SQLERRM,1,300);
INSERT INTO error_table(error_num, error_msg)
VALUES(error_number, error_message);
END;

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

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