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
- While Condition
-
- Do
-
- Loop body
-
- End while;
LOOP
- SET V_INDEX = 0;
-
- AUTHLOOP:
- LOOP
-
- V_INDEXV_INDEX = V_INDEX + 1;
- IF V_INDEX> = 100 THEN
- Leave authloop; -- equivalent to break
- End if;
- ....
- IF condition THEN
- Iterate authloop; -- equivalent to continue
- End if;
-
- SET V_INDEXV_INDEX = V_INDEX + 1;
- End loop;
REPEAT loop
- REPEAT
-
- SQL statements;
-
- UNTIL condition-exit condition
-
- END REPEAT
FOR Loop
- FOR loop_name AS
-
- SELECT … FROM
-
- DO
-
- SQL statements;
-
- 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