# What is the usage of scrollable cursor for current positioning?

DB2DatabaseBig Data Analytics

We can use SCROLLABLE CURSOR to directly point the cursor to the mentioned relative position. The relative position is the position of the row in the result table from the current row. For example, consider the table below.

ORDER_IDORDER_DATE
A223672020-07-28
A667562020-07-28
A778902020-07-29
A968322020-07-29

If the cursor is currently pointing to the 2nd absolute row i.e, ORDER_ID A66756 then the relative +2 position will be ORDER_ID A96832 and relative -1 position will be ORDER_ID A22367.

The syntax to use relative position in FETCH statement is−

EXEC SQL
FETCH RELATIVE +2 ORDER_CURR
INTO :ORDER-ID, :ORDER-DATE
END-SQL
Updated on 15-Sep-2020 11:14:12