You are on page 1of 2

Cursor

It is a private sql area


It is classified into 2 types
a) Implicit Cursor
b) Explicit Cursor

Implicit Cursor : It invokes automatically for insert, update and delete statements
and even it invokes for select statement , if it returns only one record

Explicit Cursor : It is required to retrieve more than one record by using select
statement from database table.

To use explicit cursor the following steps are required


1) Cursor Declaration (Memory Allocation)
2) Open Cursor( Retrieval Process)
3) Fetch Cursor (Fetch Process)
4) Close Cursor (Memory Deallocation)

Cursor Declaration
Syntax : cursor <cursorname> is select,......
eg: cursor ec is select * from emp;

Creating Cursor Varaible


Syntax : <cursorvariable> <cursorname>%rowtype;
eg: v_ec ec%rowtype;
Open Cursor
Syntax : open <cursorname>;
eg: open ec;

Fetch Cursor
Syntax : fetch <cursorname> into <cursorvariable>;
eg: fetch ec into v_ec;

Close Cursor
Syntax : close <cursorname>;
eg: close ec;

Cursor Attributes
%isopen : It returns true if cursor is already opened otherwise false.
Syntax : <cursorname>%isopen

%found : It return true if the record found to fetch otherwise false


Syntax : <cursorname>%found

%notfound : It return true if the record not found to fetch otherwise false
Syntax : <cursorname>%notfound

%rowcount : It return number of records fetched from active set


Syntax : <cursorname>%rowcount

You might also like