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

Write SQL queries to solve the following specifications. Include the query AND THE OUTPUT.  A screen dump of the output is acceptable. Show as many rows as you can. A screen dump i

COMMIT Statement The COMMIT statement explicitly makes everlasting changes to the database during the present transaction. The Changes made to the database are not considered e

Effects of NULL for Table Expression Here's an important distinction between expressions denoting tables and expressions denoting multisets of rows: a table expression cannot

%NOTFOUND The %NOTFOUND is the logical opposite of the %FOUND. The %NOTFOUND yields TRUE when an INSERT, UPDATE, or DELETE statement affected no rows, or the SELECT INTO state

Rephrase Conditional Control Statements When computing a logical expression, the PL/SQL uses short-circuit evaluation. That is, the PL/SQL stops evaluating the expression as s

Use External Routines The PL/SQL is particular for the SQL transaction processing. Therefore, several tasks are more quickly completed in a lower-level language like C that is

Declaring Objects: You can use the object types wherever built-in types like CHAR or NUMBER can be used. In the block below, you can declare object r of type Rational. Then, yo

When Are Constraints Checked Under the model constraints are conceptually checked at all statement boundaries (and only at statement boundaries). By default the same is true

Deleting Objects You can use the DELETE statement to eradicate objects from an object table. To eradicate objects selectively, you use the WHERE clause, as shown below: BEG