I have the following script. very simple just to see if this will work but unfortunately, I was not able to make it work. Care to tell me what is wrong?
==========================================
DECLARE GLOBAL TEMPORARY TABLE T1_TBL
( ID BIGINT,
NAME VARCHAR(200)
)
WITH REPLACE
ON COMMIT PRESERVE ROWS;
INSERT INTO session.T1_TBL
values(1,'grapes');
INSERT INTO session.T1_TBL
values(3,'apples');
INSERT INTO session.T1_TBL
values(3,'orange');
DECLARE C1 CURSOR FOR
SELECT name, id
FROM session.T1_TBL
FOR UPDATE OF name;
OPEN C1;
myLoop:
LOOP
fetch C1 INTO :name, :id;
if :id = 3 then
UPDATE session.T1_TBL
SET name = :name concat 'Alive';
end if;
END LOOP myLoop;
close C1;
commit;
==========================================
Running this script gave me the following error:
===============================
myLoop: LOOP fetch C1 INTO :name, :id
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "myLoop" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "<values>".
SQLSTATE=42601
SQL0104N An unexpected token "myLoop" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<values> ".
===============================
I just want to make it work and see how cursor works in reading the resultset per row.
Please help. Many thanks.