KEYSET CURSOR

This is the logical area, which is useful only when there is a primary key in the table. This logical area holds only Primary Key column values. Based on the key column values in the logical area (Cursor) the rest column values are coming from physical area (Table).

Example: DECLARE KC CURSOR KEYSET FOR SELECT * FROM DEPT

OPEN KC

FETCH FIRST FROM KC

10 SALES LONDON

UPDATE DEPT SET LOC=’LOSSANGLES’ WHERE LOC=’LONDON’

FETCH FIRST FROM KC

10 SALES LONDON

UPDATE DEPT SET DEPTNO=15 WHERE DEPTNO=10

FETCH FIRST FROM KC

0 NULL NULL

CLOSE KC

OPEN KC

FETCH FIRST FROM KC

15 SALES LONDON

CLOSE KC

DEALLOCATE KC

Note: Dynamic updations are not possible on key column of the keyset cursor, we have to close the cursor and we need to reopen it for the modified values.
Share/Bookmark

No comments: