Holes in the result table of a scrollable cursor
A hole in the result table means that the result table does not shrink to fill the space of deleted rows. It also does not shrink to fill the space of rows that have been updated and no longer satisfy the search condition. You cannot access a delete or update hole. However, you can remove holes in specific situations.
- Scrollable cursors that are declared as INSENSITIVE or SENSITIVE
STATIC follow a static model, which means
that Db2 determines the size
of the result table and the order of the rows when you open the cursor.
Deleting or updating rows after a static cursor is open can result in holes in the result table. See Removing a delete hole or update hole.
- Scrollable cursors
that are declared as SENSITIVE DYNAMIC follow a dynamic
model, which means that the size and contents of the
result table, and the order of the rows, can change after you open
the cursor.
A dynamic cursor scrolls directly on the base table. If the current row of the cursor is deleted or if it is updated so that it no longer satisfies the search condition, and the next cursor operation is FETCH CURRENT, then Db2 issues an SQL warning.
The following examples demonstrate how delete and update holes can occur when you use a SENSITIVE STATIC scrollable cursor.
Creating a delete hole with a static scrollable cursor:
EXEC SQL DECLARE C3 SENSITIVE STATIC SCROLL CURSOR FOR
SELECT COL1
FROM A
FOR UPDATE OF COL1;EXEC SQL OPEN C3;
EXEC SQL FETCH ABSOLUTE +3 C3 INTO :HVCOL1;
EXEC SQL DELETE FROM A WHERE CURRENT OF C3;After you execute the positioned delete statement, the third row is deleted from the result table, but the result table does not shrink to fill the space that the deleted row creates.
Creating an update hole with a static scrollable cursor
EXEC SQL DECLARE C4 SENSITIVE STATIC SCROLL CURSOR FOR
SELECT COL1
FROM A
WHERE COL1<6;EXEC SQL OPEN C4;
UPDATE A SET COL1=COL1+1;After you execute the searched UPDATE statement, the last row no longer qualifies for the result table, but the result table does not shrink to fill the space that the disqualified row creates.