Error handling in pl/sql, PL-SQL Programming

Error Handling

The PL/SQL makes it easy to detect and process the predefined and user-defined error conditions known as exceptions. Whenever an error occurs, an exception is raised. That is, the normal execution stops and control transfers to the exception-handling part of your PL/SQL block or subprogram. To handle the raised exceptions, you write individual routines known as exception handlers.

The Predefined exceptions are raised implicitly by the runtime system. For e.g., when you try to divide a number by zero, the PL/SQL raises the predefined exception ZERO_ DIVIDE automatically. You should raise user-defined exceptions explicitly with the help of the RAISE statement.

You can define the exceptions of your own in the declarative part of any PL/SQL block or subprogram. In the executable part, you ensure for the condition that requires special attention. If you find that the condition exists, then you can execute the RAISE statement. In the example below, you calculate the bonus earned by a salesperson. The bonus depends on the salary and commission. So, if the commission is zero or null, you raise the exception comm_missing.

DECLARE

...

comm_missing EXCEPTION; -- declare exception

BEGIN

...

IF commission IS NULL THEN

RAISE comm_missing; -- raise exception

END IF;

bonus := (salary * 0.10) + (commission * 0.15);

EXCEPTION

WHEN comm_missing THEN ... -- process exception

Posted Date: 10/2/2012 1:53:35 AM | Location : United States







Related Discussions:- Error handling in pl/sql, Assignment Help, Ask Question on Error handling in pl/sql, Get Answer, Expert's Help, Error handling in pl/sql Discussions

Write discussion on Error handling in pl/sql
Your posts are moderated
Related Questions
In Packages The Forward declarations also group logically related subprograms in the package. The subprogram specifications go in the package specification, & the subprogram b

Project Description: This is stage 1 of a larger conversion project. We are converting a traditional Server/Client application written in Access 2007 into a web interface with S

Case Sensitivity Similar to all the identifiers, the variables, the names of constants, and parameters are not case sensitive. For illustration, PL/SQL considers the following n

TYPES OF EVOLUTION - Sequential evolution                  :                    Minor changes in the gene pool of a population from one generation to the next, with the resul

Left and Right Joins LEFT OUTER JOIN can be used when you want to retrieve the data from the main table (table1) even if there is no match in other tables (table_2, table_3...

Assignment Statement: The assignment statement sets the present value of the variable, parameter, field, or element. The statement consists of an assignment target followed by

If two relations R and S are joined, then the non matching tuples of both R and S are ignored in __________________.

Effects of NULL in Aggregate Operator - SQL Let aggop(x) be an invocation of some aggregate operator aggop in SQL, where x is an expression (usually an open expression) to be

Project Description: I want to write some SQL statements. The things I need are between pages 5-7. The only problem is that i want it till tomorrow. Skills required is SQL

Using Aggregation on Nested Tables Example is the most direct translation of its counterpart in the theory book that can be obtained in SQL but it is so over-elaborate that no