问题:如果在游标中更新数据后,提交事务,游标将不会执行第二记录,即游标记录结束
DECLARE cur_Temp CURSOR FOR
SELECT ID,NAME FROM TABLE1;
OPEN cur_Temp;
DO WHILE TRUE
FETCH cur_Temp INTO :l_ID,:l_Name
IF SQLCA.SQLCode <> 0 THEN EXIT
UPDATE TABLE2 SET NAME=:l_Name WHERE ID:=l_ID;
COMMIT;
END IF
LOOP
CLOSE cur_Temp;
改正办法:
DECLARE cur_Temp CURSOR FOR
SELECT ID,NAME FROM TABLE1;
OPEN cur_Temp;
DO WHILE TRUE
FETCH cur_Temp INTO :l_ID,:l_Name
IF SQLCA.SQLCode <> 0 THEN EXIT
UPDATE TABLE2 SET NAME=:l_Name WHERE ID:=l_ID;
END IF
LOOP
CLOSE cur_Temp;
COMMIT;