How will you 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: 15-Sep-2020

699 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements