Hi,
I am new to DB2 and cursor development and am running into a problem with what I consider a simple enough cursor. When I run the example below I get this error:
"SQL0206N "V_USER_ID" is not valid in the context where it is used. LINE NUMBER=12..."
Code:
CREATE PROCEDURE DB2INST1.Proc1()
LANGUAGE SQL
P1: BEGIN
DECLARE v_USER_ID VARCHAR(20);
DECLARE c1 CURSOR FOR SELECT USR_ID FROM USR_APPL_PRFL_ASSN WHERE APP_NM = 'ABC1';
OPEN c1;
LOOP
FETCH c1 INTO v_USER_ID;
INSERT INTO USR_WRK_GRP(WRK_GRP_ID, USR_ID) VALUES (7, v_USR_ID);
INSERT INTO USR_WRK_GRP(WRK_GRP_ID, USR_ID) VALUES (8, v_USR_ID);
END LOOP;
CLOSE c1;
END P1
;
Basically I am trying to take the output from the select statement and use that then as a parameter in my insert statements.
What is wrong here? I am using RapidSQL to run this.
Thanks