Cursors

Cursor is a logical area, which is used to retrieve a particular nth record. Selecting a particular nth record is not possible through physical area (Table). In such situations one logical area (Cursor) we can create and then we can select a particular nth record. Cursors are used to store transaction information temporarily.

Types of Cursors:

1. Static Cursor
2. Dynamic Cursor
3. Keyset Cursor
4. Forward_Only Cursor

Syntax to declare the Cursor:

DECLARE CURSORNAME CURSOR CURSORTYPE FOR SELECT * FROM TABLENAME

Syntax to open the Cursor:

Open cursorname

Syntax to fetch the records from cursor:

Fetch {first/next/prior/last/absolute/relative n} from cursorname

Syntax to close the cursor:

Close cursorname

Syntax to deallocate the cursor:

Deallocate cursorname

FIRST: Fetches first record from the cursor

NEXT: Fetches next record from the current position of the cursor

PRIOR: Fetches previous record from the current position of the cursor

LAST: Fetches last record from the cursor

ABSOLUTE N: Fetches nth record from the top of the cursor if n positive fetches the nth record from bottom of the cursor if n is negative. Where n is an integer.

RELATIVE N: Fetches nth next record from current position of the cursor if n is positive fetches nth previous record from the current position of the cursor if n is negative where n is an integer.
Share/Bookmark

No comments: