Four Common DB2 cycle statements

Source: Internet
Author: User

DB2 cycle statements are frequently used when you use DB2 databases. The following describes four commonly used DB2 cycle statements, we hope that you will have a better understanding of the DB2 circular statements.

Normal Loop

While Loop

 
 
  1. While Condition
  2.  
  3. Do
  4.  
  5. Loop body
  6.  
  7. End while;

LOOP

 
 
  1. SET V_INDEX = 0;
  2.  
  3. AUTHLOOP:
  4. LOOP
  5.  
  6. V_INDEXV_INDEX = V_INDEX + 1;
  7. IF V_INDEX> = 100 THEN
  8. Leave authloop; -- equivalent to break
  9. End if;
  10. ....
  11. IF condition THEN
  12. Iterate authloop; -- equivalent to continue
  13. End if;
  14.  
  15. SET V_INDEXV_INDEX = V_INDEX + 1;
  16. End loop;

REPEAT loop

 
 
  1. REPEAT
  2.  
  3. SQL statements;
  4.  
  5. UNTIL condition-exit condition
  6.  
  7. END REPEAT

FOR Loop

 
 
  1. FOR loop_name AS   
  2.  
  3.    SELECT … FROM   
  4.  
  5. DO   
  6.  
  7.    SQL statements;   
  8.  
  9. END FOR;   

Implementation of creating a database in DB2

DB2 database authorization

DB2 Authentication Overview

DB2 rename a table and view table information

DB2 database commands

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.