How will you fetch the 2nd column from the current position of the scrollable cursor defined on ORDERS DB2 table?

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