DB2 In CURSOR with Multi Record Fetching

5 different best examples with Rowset positioning in DB2. These example also you can use for DELETE, UPDATE and SELECT multiple rows.

Retrieve first 20 rows with rowset positioning- 

EXEC SQL 

 FETCH NEXT ROWSET FROM C1 FOR 20 ROWS 

 INTO :HVA-EMPNO, :HVA-LASTNAME, :HVA-SALARY :INDA-SALARY 

END-EXEC.

UPDATE rows from Rowset positioning – The below query update salary to 5000 in all the rows of rowset result table.

EXEC SQL 

 UPDATE DSN8B10.EMP SET SALARY = 50000 

 WHERE CURRENT OF C1 

END-EXEC.

DELETE Rows from rowset positioning – Below query deletes all the rows of rowset positioning result table.

EXEC SQL 

 DELETE FROM DSN8B10.EMP 

 WHERE CURRENT OF C1 

END-EXEC.
Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.