Exception Handling
Exception Handling
HANDLING
What is an exception:
An exception is an error condition
an exceptions.
What is exception handling?
The mechanism for solving such an
Types of exception:
1. Pre-defined /System-defined
Exceptions
2. User- Defined Exceptions
System-defined exceptions/Predefine
exceptions/Built-in exceptions:
System defined exception are defined and
default.
For example, the predefined exception
part of a subprogram.
PL/SQL allow us to define our own
DECLARE
exception_name
EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name
THEN statement;
END;
CURSORS
A cursor is a pointer to this context area.
PL/SQL controls the context area through a
cursor.
A cursor is a temporary work area created in
active set.
Each cursor contains the followings 4
steps-
1. Declare Cursor: In this part we declare
variables and return a set of values.
2. Open: This is the entering part of the cursor.
3. Fetch: Used to retrieve the data row by row
from a cursor.
4. Close: This is an exit part of the cursor and
used to close a cursor.
Example:
Declare
enumemp.eno%type;
enemp.ename%type;
Cursor cur is select eno, ename from emp where
jobname = “mgr”;
Begin
Open cur;
Loop Fetch cur into enum,en;
Exit when cur%NOTFOUND;
Dbms_output.put_line(„emp num ‟||enum||‟ emp
name „||en);
End loop;
Close cur;
End;
/
Each There are two types of cursors:
1.Implicit cursors
2.Explicit cursors