Error Handling In Oracle Plsql
Churchill Run-time errors arise from design faults, coding mistakes, hardware failures, and many other sources. Although you cannot anticipate all possible errors, you can plan to handle certain kinds of errors meaningful to your PL/SQL program. With many programming languages, unless you disable error checking, a run-time error such as stack overflow or division by zero stops normal processing and returns control to the operating system. With PL/SQL, a mechanism called exception handling lets you "bulletproof" your program so that it can continue operating in the presence of errors. This chapter discusses the following topics: Overview of PL/SQL Error Handling Advantages of PL/SQL Exceptions Predefined PL/SQL Exceptions Defining Your Own PL/SQL Exceptions How PL/SQL Exceptions Are Raised How PL/SQL Exceptions Propagate Reraising a PL/SQL Exception Handling Raised PL/SQL Exceptions Tips for Handling PL/SQL Errors Overview of PL/SQL Error Handling In PL/SQL, a warning or error condition is called an exception. Exceptions can be internally defined (by the run-time system) or user defined. Examples of internally defined exceptions include division by zero and out of memory. Some common internal exceptions have predefined names, such as ZERO_DIVIDE and STORAGE_ERROR. The other internal exceptions can be given names. You can define exceptions of your own in the declarative part of any PL/SQL block, subprogram, or package. For example, you might define an exception named insufficient_funds to flag overdrawn bank accounts. Unlike internal exceptions, user-defined exceptions must be given names. When an error occurs, an exception is raised. That is, normal execution stops and control transfers to the exception-handling part of your PL/SQL block or subprogram. Internal exceptions are raised implicitly (automatically) by the run-time system. User-defined exceptions must be raised explicitly by RAISE statement
are called exceptions. Note: The language of warning and error messages depends on the NLS_LANGUAGE parameter. For information about this parameter, see Oracle Database Globalization Support Guide. Topics Compile-Time Warnings Overview of Exception Handling Internally Defined Exceptions Predefined Exceptions User-Defined Exceptions Redeclared Predefined Exceptions Raising Exceptions Explicitly Exception Propagation Unhandled Exceptions Error Code and Error Message Retrieval Continuing Execution After Handling Exceptions Retrying Transactions After Handling Exceptions See Also: "Exception Handling in Triggers" "Handling FORALL Exceptions After FORALL Statement Completes" Tip: If you have problems creating or running PL/SQL code, check the Oracle Database trace files. The https://docs.oracle.com/cd/B10500_01/appdev.920/a96624/07_errs.htm USER_DUMP_DEST initialization parameter specifies the current location of the trace files. You can find the value of this parameter by issuing SHOW PARAMETER USER_DUMP_DEST. For more information about trace files, see Oracle Database Performance Tuning Guide. Compile-Time Warnings While compiling stored PL/SQL units, the PL/SQL compiler generates warnings for conditions that are not serious enough to cause errors and prevent compilation—for example, using a deprecated PL/SQL feature. To see https://docs.oracle.com/cloud/latest/db112/LNPLS/errors.htm warnings (and errors) generated during compilation, either query the static data dictionary view *_ERRORS (described in Oracle Database Reference) or, in the SQL*Plus environment, use the command SHOW ERRORS. The message code of a PL/SQL warning has the form PLW-nnnnn. For the message codes of all PL/SQL warnings, see Oracle Database Error Messages. Table 11-1 summarizes the categories of warnings. Table 11-1 Compile-Time Warning Categories Category Description Example SEVERE Condition might cause unexpected action or wrong results. Aliasing problems with parameters PERFORMANCE Condition might cause performance problems. Passing a VARCHAR2 value to a NUMBER column in an INSERT statement INFORMATIONAL Condition does not affect performance or correctness, but you might want to change it to make the code more maintainable. Code that can never run By setting the compilation parameter PLSQL_WARNINGS, you can: Enable and disable all warnings, one or more categories of warnings, or specific warnings Treat specific warnings as errors (so that those conditions must be corrected before you can compile the PL/SQL unit) You can set the value of PLSQL_WARNINGS for: Your Oracle database instance Use the ALTER SYSTEM statement, described in Oracle Database SQL Language Reference. Your session Use the ALTER SESSION statement, described in Oracle Database SQL
Server https://www.techonthenet.com/oracle/exceptions/ MySQL MariaDB PostgreSQL SQLite MS Office Excel Access Word Web Development HTML CSS Color Picker Languages http://www.dba-oracle.com/plsql/t_plsql_error_handling.htm C Language More ASCII Table Linux UNIX Java Clipart Techie Humor Oracle Basics Oracle Advanced Oracle error handling Cursors Oracle Exception Handling Named Programmer-Defined Exception Named System Exception WHEN OTHERS Clause SQLCODE SQLERRM Oracle Foreign Keys Oracle Loops/Conditionals Oracle Transactions Oracle Triggers String/Char Functions Numeric/Math Functions Date/Time Functions Conversion Functions Analytic error handling in Functions Advanced Functions Oracle / PLSQL: Exception Handling The following is a list of topics that explain how to use Exception Handling in Oracle/PLSQL: Named System Exceptions Named Programmer-Defined Exceptions WHEN OTHERS Clause SQLCODE Function SQLERRM Function Oracle Error Messages Share this page: Advertisement Back to top Home | About Us | Contact Us | Testimonials | Donate While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy. We use advertisements to support this website and fund the development of new content. Copyright © 2003-2016 TechOnTheNet.com. All rights reserved.
SQL TuningSecurityOracle UNIXOracle LinuxMonitoringRemote supportRemote plansRemote servicesApplication Server ApplicationsOracle FormsOracle PortalApp UpgradesSQL ServerOracle ConceptsSoftware SupportRemote Support Development Implementation Consulting StaffConsulting PricesHelp Wanted! Oracle PostersOracle Books Oracle Scripts Ion Excel-DB Don Burleson Blog
Error Handling in PL/SQL Oracle Tips by Burleson Consulting The following Tip is from the outstanding book "Oracle PL/SQL Tuning: Expert Secrets for High Performance Programming" by Dr. Tim Hall, Oracle ACE of the year, 2006: When PL/SQL detects an error, normal execution stops and an exception is raised. This exception can be captured and processed within the block by the exception handler if it is present. If the block does not contain an exception handler section, the exception propagates outward to each successive block until a suitable exception handler is found or the exception is presented to the client application. Oracle provides many predefined exceptions for common error conditions, like NO_DATA_FOUND when a SELECT ... INTO statement returns no rows. The following example shows how exceptions are trapped using the appropriate exception handler. It also shows how to return the username associated with a specific user_id value. SET SERVEROUTPUT ON DECLARE l_user_id all_users.username%TYPE := 0; l_username all_users.username%TYPE; BEGIN SELECT username INTO l_username FROM all_users WHERE user_id = l_user_id; DBMS_OUTPUT.put_line('l_username=' || l_username); END; / l_username=SYS PL/SQL procedure successfully completed. SQL> That works fine for user_id values that exist, but look what happens when one is used that does not exist. SET SERVEROUTPUT ON DECLARE l_user_id all_users.username%TYPE := 999999; l_username all_users.username%TYPE; BEGIN SELECT username INTO l_username FROM all_users WHERE user_id = l_user_id; DBMS_OUTPUT.put_line('l_username=' || l_username); END; / DECLARE * ERROR at line 1: ORA-01403: no data found ORA-06512: at line 5 SQL> This is not a very user friendly message, so this error can be trapped and something else produc