Use an instance to explain the problem of DB2 database cursor Loop

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.