A scrollable cursor is defined on the ORDERS DB2 table. How will you fetch the 9th row of the cursor present in absolute position?

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
raja
Published on 15-Sep-2020 14:42:24
Advertisements