Introduction to the DB2 cursor Loop

Source: Internet
Author: User
Tags stored procedure example

This article mainly introduces how to use an instance to explain the problem of DB2 cursor loop. If you are curious about using an instance to explain the problem of DB2 cursor loop, the following articles will unveil its secrets. The following is a detailed description of the article. I hope you can learn from it.

The stored procedure example in this article shows that 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, so after at_end, it will immediately be equal to 1 (only one loop will exit ).

 
 
  1. DECLARE at_end INT DEFAULT 0;   
  2. DECLARE PIID INTEGER DEFAULT 0 ;   
  3. DECLARE PINT INTEGER DEFAULT 0 ;   
  4. DECLARE not_found CONDITION FOR SQLSTATE '02000';   
  5. --DECLARE PCOUNT INTEGER;   
  6. DECLARE c1 CURSOR FOR   
  7. SELECT IID FROM YH;   
  8. DECLARE CONTINUE HANDLER FOR not_found   
  9. SET at_end = 1;   
  10. OPEN c1;   
  11. SET PCOUNT=0;   
  12. ins_loop:   
  13. LOOP   
  14. FETCH c1 INTO PIID;   
  15. IF at_end <>0THEN   
  16. LEAVE ins_loop;   
  17. END IF;   
  18. SET PCOUNTPCOUNT=PCOUNT+1;   
  19. SELECT IID INTO PINT FROM YH WHERE 0=1;   
  20. END LOOP; 

The above content is an introduction to the problem of DB2 cursor loop with an instance. I hope you will gain some benefits.

The above content describes how to use an instance to explain the problem of DB2 cursor loop. I hope it will help you in this regard.

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.