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

DB2DatabaseBig Data Analytics

The SCROLLABLE CURSOR can be used to directly point the cursor position to the mentioned absolute position. The absolute position is the position of a particular row in the result table from the first row.

We can fetch the absolute position by using ABSOLUTE parameter in the FETCH statement. For example, we have to declare a scrollable cursor as below.

EXEC SQL
DECLARE ORDER_CURR SCROLL CURSOR FOR
SELECT ORDER_ID, ORDER_DATE FROM ORDERS
WHERE ORDER_DATE = ‘2020-07-29’
END-SQL

Now if we want to fetch the absolute 9th row then we will use FETCH statement like below.

EXEC SQL
FETCH ABSOLUTE +9 ORDER_CURR
INTO :ORDER-ID, :ORDER-DATE
END-SQL
Published on 15-Sep-2020 11:12:24