Extract Multiple Rows from a DB2 Table in a Single Fetch Call



We can extract multiple rows from a DB2 table in a single FETCH call using a concept of multi row fetch.

In a multi row fetch, we have to declare the cursor with the clause “WITH ROWSET POSITIONING”. The host variable in this case should be declared as an array.

Therefore, in a single fetch statement the host variable array will be populated with the multiple row data. We can traverse in the host variable array in order to access this row data.

For example, we can declare a multi fetch cursor like below−

EXEC SQL
   DECLARE ORDER_CUR WITH ROWSET POSITIONING FOR
   SELECT ORDER_ID FROM ORDERS WHERE
   ORDER_DATE = ‘2020-07-28’
END-SQL
Updated on: 2020-09-15T10:51:31+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements