Plsql Error Handling Tutorial
Contents |
Basic Syntax PL/SQL - Data Types PL/SQL - Variables PL/SQL - Constants PL/SQL - Operators PL/SQL - Conditions PL/SQL - Loops PL/SQL - Strings PL/SQL - Arrays PL/SQL - Procedures PL/SQL - Functions pl sql exception when others PL/SQL - Cursors PL/SQL - Records PL/SQL - Exceptions PL/SQL - Triggers PL/SQL
Pl Sql Exceptions
- Packages PL/SQL - Collections PL/SQL - Transactions PL/SQL - Date & Time PL/SQL - DBMS Output PL/SQL - Object user defined exception in oracle Oriented PL/SQL Useful Resources PL/SQL - Questions and Answers PL/SQL - Quick Guide PL/SQL - Useful Resources PL/SQL - Discussion Selected Reading Developer's Best Practices Questions and Answers Effective Resume Writing HR Interview
Exception Handling In Oracle 11g
Questions Computer Glossary Who is Who PL/SQL - Exceptions Advertisements Previous Page Next Page An error condition during a program execution is called an exception in PL/SQL. PL/SQL supports programmers to catch such conditions using EXCEPTION block in the program and an appropriate action is taken against the error condition. There are two types of exceptions: System-defined exceptions User-defined exceptions Syntax for Exception Handling The General pl sql exception handling best practices Syntax for exception handling is as follows. Here you can list down as many as exceptions you want to handle. The default exception will be handled using WHEN others THEN: DECLARE
errors. The latter are called exceptions. Note:
Raise Application Error In Oracle
The language of warning and error messages depends on the
Types Of Exception In Oracle
NLS_LANGUAGE parameter. For information about this parameter, see Oracle Database Globalization Support Guide. Topics exception handling in oracle interview questions 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 https://www.tutorialspoint.com/plsql/plsql_exceptions.htm 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 USER_DUMP_DEST initialization https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm 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 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 unexpe
own exception and raise it in your code. Introducing to PL/SQL Exception In PL/SQL, any kind of errors is treated as exceptions. An exception is defined as a special condition that change http://www.plsqltutorial.com/plsql-exception/ the program execution flow. The PL/SQL provides you with a flexible and powerful way to handle such exceptions. PL/SQL catches and handles exceptions by using exception handler architecture. Whenever an exception occurs, it is raised. The current PL/SQL block execution halts and control is passed to a separate section called exception section. In the exception section, you can check what kind of exception has been in oracle occurred and handle it appropriately. This exception handler architecture enables separating the business logic and exception handling code hence make the program easier to read and maintain. PL/SQL Exception There are two types of exceptions: System exception: the system exception is raised by PL/SQL run-time when it detect an error. For example, NO_DATA_FOUND exception is raised if you select a non-existing record from the database. Programmer-defined exception: pl sql exception the programmer-defined exception is defined by you in a specific application. You can map exception names with specific Oracle errors using the EXCEPTION_INIT pragma. You can also assign a number and description to the exception using RAISE_APPLICATION_ERROR. Defining PL/SQL Exception An exception must be defined before it can be raised. Oracle provides many predefined exceptions in the STANDARD package. To define an exception you use EXCEPTION keyword as below: EXCEPTION_NAME EXCEPTION; 1 EXCEPTION_NAME EXCEPTION; To raise exception that you've defined you use the RAISE statement as follows: RAISE EXCEPTION_NAME; 1 RAISE EXCEPTION_NAME; In the exception handler section, you use can handle the exception as usual. The following example illustrates the programmer-defined exceptions. We get the salary of an employee and check it with the job's salary range. If the salary is below the range, we raise an exception BELOW_SALARY_RANGE. If the salary is above the range, we raise the exception ABOVE_SALARY_RANGE just make it simple for demonstration. SET SERVEROUTPUT ON SIZE 100000; DECLARE -- define exceptions BELOW_SALARY_RANGE EXCEPTION; ABOVE_SALARY_RANGE EXCEPTION; -- salary variables n_salary employees.salary%TYPE; n_min_salary employees.salary%TYPE; n_max_salary employees.salary%TYPE; -- input employee id n_emp_id employees.employee_id%TYPE := &emp_id; BEGIN SELECT salary, min_salary, max_salary INTO n_salary, n_min