DB2中的游标如何死循环了?
DB2中的游标怎么死循环了?????
我写了一个存储过程,里面用到了游标,测试的时候发现死循环了,应该只有10条数据的,但在test_log中出现了上万条直到日志满。我在test_log中查了一下,从第10条开始插入的值是一样的。
怎么改啊???
DECLARE str integer;
DECLARE cursor1 CURSOR WITH RETURN FOR
select inmemid from crns.git_aa fetch first 10 row only;
OPEN cursor1;
loop_1:
loop
fetch cursor1 into str;
insert into crns.test_log (log2) values(str);
end loop loop_1;
commit;
close cursor1;
------解决方案--------------------
DECLARE str integer;
declare sqlcode integer default 0;
DECLARE cursor1 CURSOR WITH RETURN FOR
select inmemid from crns.git_aa fetch first 10 row only;
OPEN cursor1;
loop_1:
loop
fetch cursor1 into str;
if sqlcode=100 then leave loop_1;
end if;
insert into crns.test_log (log2) values(str);
end loop loop_1;
commit;
close cursor1;
我写了一个存储过程,里面用到了游标,测试的时候发现死循环了,应该只有10条数据的,但在test_log中出现了上万条直到日志满。我在test_log中查了一下,从第10条开始插入的值是一样的。
怎么改啊???
DECLARE str integer;
DECLARE cursor1 CURSOR WITH RETURN FOR
select inmemid from crns.git_aa fetch first 10 row only;
OPEN cursor1;
loop_1:
loop
fetch cursor1 into str;
insert into crns.test_log (log2) values(str);
end loop loop_1;
commit;
close cursor1;
------解决方案--------------------
DECLARE str integer;
declare sqlcode integer default 0;
DECLARE cursor1 CURSOR WITH RETURN FOR
select inmemid from crns.git_aa fetch first 10 row only;
OPEN cursor1;
loop_1:
loop
fetch cursor1 into str;
if sqlcode=100 then leave loop_1;
end if;
insert into crns.test_log (log2) values(str);
end loop loop_1;
commit;
close cursor1;