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 


 

 

 


 

 

 
 

Ignoring Oracle ORA Errors in PL/SQL

Expert Oracle Database Tips by Burleson Consulting

March 21, 2015

 

Oracle PL/SQL provides an exception clause to allow you to stop execution of your program whenever Oracle returns a specific ORA-xxxx error. 

Oracle provides the generic when others clause for trapping all non-zero error codes. 

However, there are cases when you expect an Oracle error to be thrown, such as a PL/SQL code that creates a table, and ignores the error if the table already exists. (The ORA-00955 error below).

Remember, PL/SQL is separate from the Oracle database, and whenever you call Oracle, you want to check the return code to ensure that Oracle has done what you wanted.  See these important notes on PL/SQL error handling.  Also note that you can handle PL/SQL exceptions when using bulk operators (forall and bulk collect)

It's easy to use the built-in values with the PL/SQL exceptions clause, but this list does not cover all 1,000+ possible Oracle errors. 

Let's look at how to define a custom exception for an Oracle ORA- error code.

 Defining a custom Oracle error exception in PL/SQL

Oracle has over 1,000 distinct error codes, and this is how to translate an ORA-0nnn to a SQLCODE.

For example, let's assume that we want to ignore the ORA-00955 error, where a table already exists.  The SQLCODE is the same as the Oracle error code with the leading ORA-000's stripped off:

Oracle error         SQLCODE
ORA-01555            -1555
ORA-00600            -600
ORA-03113            -3113
ORA-12560            -12560
ORA-03113            -3113
etc . . .

Below we trap an ORA-00955 error which translates into a -955 SQLCODE.  We define a custom pragma exception TableExists) and then check this Boolean in the EXCEPTION clause:

DECLARE
   TableExists EXCEPTION;
   pragma exception_init(TableExists,-955);
   sql_stmt varchar2(50) := 'create table temp (col1 number)';
BEGIN
   execute immediate sql_stmt;
/*+ Ignore ORA-955 errors when the table already exists) */
EXCEPTION when TableExists then NULL;
END;

Here is another method for ignoring an expected non-zero return code from Oracle, using the important when others clause to abort the PL/SQL if an unexpected error comes from Oracle:

EXCEPTION
WHEN OTHERS THEN
if (sqlcode=-955) then NULL
else
RAISE;
end if;

Using these simple techniques we can trap dozens of expected errors in our PL/SQL program while still stopping the program when we hit an unexpected non-zero return code from Oracle.

 For working examples of the exceptions clause see the download from the book Easy PL/SQL Programming and the code depot in the great book PL/SQL Tuning Secrets by Dr. Timothy Hall.

 
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 -  2016

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