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
Grouping and Ungrouping in SQL Example specifying EXAM_MARK in place of COURSE in the main FROM clause. Example: Obtaining C_ER2 from EXAM_MARK SELECT CourseId, CAST

%ROWTYPE: This attribute gives a record type which represents a row in the database table or a row fetched from a formerly declared cursor. The Fields in the record and corresp

Authorize and fetch data from Instagram Project Description: Incorporate Instagram feed on mobile site platform: c#, ms sql, jquerymobile, jquery Web admin Author

Use of Table Expressions - Expressing Constraint Conditions With the exception of key constraints, the examples in the theory book all explicitly reference at least one relvar

Define basic operators of relational algebra with an example each

Use Serially Reusable Packages To help you to manage the use of memory, the PL/SQL gives the pragma SERIALLY_ REUSABLE that mark some packages as serially reusable . So mark

Overloading The PL/SQL overloads the subprogram names. That is, you can use similar name for few different subprograms as long as their formal parameters differ in the number

Semidifference via NOT IN and a subquery SELECT StudentId FROM IS_CALLED WHERE Name = 'Devinder' AND StudentId NOT IN (SELECT StudentId FROM IS_ENROLLED_ON WHER

Explicit Cursors The set of rows returned by the query can include zero, one, or multiple rows, depending on how many rows meet your search criteria. Whenever a query returns

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