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.



comm_missing EXCEPTION; -- declare exception



IF commission IS NULL THEN

RAISE comm_missing; -- raise exception


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


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
JOIN and AND in SQL In this Section is all about one operator, JOIN. SQL's closest counterpart, NATURAL JOIN, has already been covered. Here we look at several other "join" op

ROWNUM The ROWNUM returns a number representing the order in which a row was selected from the table. The first row selected has a ROWNUM of 1; the second row has a ROWNUM of

Using Host Arrays The Client-side programs can use anonymous PL/SQL blocks to bulk-bind input and output host arrays. However, this is the well-organized way to pass the colle

Nested Tables versus Index-by Tables The Index-by tables and nested tables are just similar. For e.g.  They have similar structure and their individual elements are accessed in

Description: Demonstrate your knowledge of PL/SQL programming by writing and thoroughly testing triggers and stored procedures associated with an e-commerce application that pr

Cursor Variables Similar to a cursor, cursor variable points to the current row in the result set of a multi-row query. But, dissimilar a cursor, a cursor variable can be opene

Brewbean's is implementing a new discount for return shoppers - every fifth completed order receives a 10% discount. The count of orders for a shopper is placed in a packaged varia

Boolean Values Only the values TRUE, FALSE, & NULL can be assigned to a Boolean variable. For illustration, given the declaration DECLARE done BOOLEAN; the following statements

Problem: (a) Define the following terms: (i) data mining. (ii) OLAP. (b) Differentiate between snowflake schema and star schema. Support your answer with appropriate

Fetching with a Cursor The FETCH statements retrieve the rows in the result set one at a time. After each and every fetch, the cursor advance to the next row in the result set