INSERT, UPDATE and DELETE DB2 Rowset Positioning

Example SQL queries to use rowset positioning to carry INSERT, UPDATE and DELETE of Multi rows

5 different best examples of Rowset positioning usage in DB2. These examples include to DELETE, UPDATE and SELECT multiple rows.

SELECT – FETCH FIRST 20 ROWS WITH ROWSET POSITIONING

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.

Recent Posts