DB2 SQL CURSOR : POSITIONED UPDATE & DELETE

CREATE TABLE EXAMPLETABLE (id numeric, name char(10), processedFlag char(1));

DECLARE @C1 CURSOR for 
(Select id,name from EXAMPLETABLE where processedFlag <>'Y')
FETCH @C1 into :localID, :localName
DoW(SQLCODE = 0)
---- PROCESSING LOGIC------

UPDATE EXAMPLETABLE set processedFlag ='Y'
WHERE id =localID and name = localName

FETCH @C1 into :localID, :localName
EndDO
DECLARE @C1 CURSOR for 
(Select id,name from EXAMPLETABLE where processedFlag <>'Y')
FOR UPDATE
DECLARE @C1 CURSOR for 
(Select id,name from EXAMPLETABLE where processedFlag <>'Y')
FOR UPDATE OF processedFlag ;
FETCH @C1 into :localID, :localName
DoW(SQLCODE = 0)
---- PROCESSING LOGIC------

UPDATE EXAMPLETABLE set processedFlag ='Y'
WHERE CURRENT OF @C1

FETCH @C1 into :localID, :localName
EndDO
DELETE FROM EXAMPLETABLE WHERE CURRENT OF @C1

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store