Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Make a custom Oracle error message

Oracle Database Tips by Donald BurlesonDecember 12, 2015

Question:  I want to make fully documented custom error messages in my PL/SQL application and integrate the error messages the same as any other ORA-xxxx message.  How do you document a new error and make it work with the oerr utility?

Answer:  Adding custom Oracle error messages is not difficult.  Any PL/SQL programmers know that they can create any custom ZZZ-1234 error number to be returned by their code.
 
You can use utl_file.put_line to write to the alert log , and you can use this same approach to write customized error messages.  Here we write a ZZZ-1234 custom error message to the Oracle alert log:

-- ******************************************************
-- Set the utl_file_dir
-- ******************************************************
alter system set utl_file_dir = ?:alert_loc?);


-- ******************************************************
-- Open the alert log file for write access
-- ******************************************************
utl_file.fopen(':alert_loc',?alertprod.log?,'W');

-- ******************************************************
-- Write the custom message to the alert log file
-- ******************************************************
dbms_output.put_line('ZZZ-1234  This guy has bad credit');

 
But writing s custom alert message is only half the story, you must also document the error cause and error action within the Oracle error message utility (oerr).
 
The oerr messages are placed into groups based on the prefix for the files.  The facility information is read from the facility file located in $ORACLE_HOME/lib/facility.lis.

zzz:custom:*:
tns:rdbms:*:
ora:rdbms:*:

Mapping the facility files to the error messages

In the case above the customized message zzz:custom points to a message file located at:
 
$ORACLE_HOME/zzz/custom/mesg/zzzus.msg

So, by creating the entry zzz:custom:*:  in $ORACLE_HOME/lib/facility.lis, Oracle knows that any message like zzz will reside in the file located at $ORACLE_HOME/zzz/custom/mesg/zzzus.msg.
 
The Oracle message facility is very simple, using a grep-like command to extract error messages from an ordinary flat file.

Using oerr with custom messages

The oerr script is located in the $ORACLE_HOME/bin/oerr.ksh directory.  The oerr command is a Korn Shell script that looks something like this script:
 
oerr=`awk "BEGIN { found = 0; }/^[0]*$Code/ { found = 1; print ; next;}/^\/\// { if (found) {print; } next; }{ if (found) { exit; } }" $Msg_File`
 
You can also make your own oerr using grep:
 
oracle> cd $ORACLE_HOME/zzz/custom/mesg
oracle> grep ?i 1234 zzzus.msg
 
 
See here how to make an oerr for Windows:
 
The oerr utility accepts two arguments:
 
1 - The facility (ORA if omitted)
2 - The error number
 

oracle> oerr cust 007
 
00007, 00000, "James Bond Error"
// *Cause:  You must have has Pussy Galore
// *Action: See your doctor for n STD shot


oracle> per zzz 1234

1234.0000, 'this guy has bad credit?
// *Cause:  This guy has no money
// *Action: give this bum some cash


 For more details on using the oerr utility, see the book Advanced Oracle Utilities


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster