Introduction: DB2 database cursor LoopWhat is the situation? In this article, we will use an instance analysis to explain it to you.
The expected number of cycles is the number of rows in the yh table. Because select iid into pint from yh where 0 = 1; No rows are returned, at_end will immediately exit after 1 loop ).
DECLARE at_end int default 0;
Declare piid integer default 0;
Declare pint integer default 0;
DECLARE not_found condition for sqlstate '201312 ';
-- Declare pcount integer;
DECLARE c1 CURSOR
Select iid from yh;
Declare continue handler for not_found
SET at_end = 1;
OPEN c1;
Set pcount = 0;
Ins_loop:
LOOP
FETCH c1 into piid;
IF at_end <> 0 THEN
LEAVE ins_loop;
End if;
Set pcount = PCOUNT + 1;
Select iid into pint from yh where 0 = 1;
End loop;
This article is to embody the abstract technology of the DB2 database, so that the analysis of application instances makes the problem easier to understand. I hope you can summarize and apply it to your work, hope to help you.