SQL$HELP72.HLB  —  LOOP Control, Examples
    Example 1: Executing a loop statement

    SQL> create table ENROLLMENTS
    cont>     (last_name          char(20),
    cont>      first_name         char(10),
    cont>      middle_initial     char,
    cont>      class_name         char(10));
    SQL>
    SQL> begin
    cont> declare :n integer default 5;
    cont> loop
    cont>     insert into ENROLLMENTS
    cont>       values ('Jones', 'Robert', 'A',
    cont>               'Class ' || CAST(:n as char(1)));
    cont>     set :n = :n - 1;
    cont>     if :n <= 0 then
    cont>         leave;
    cont>     end if;
    cont> end loop;
    cont> end;
    SQL>
    SQL> select * from ENROLLMENTS;
     LAST_NAME              FIRST_NAME   MIDDLE_INITIAL   CLASS_NAME
     Jones                  Robert       A                Class 5
     Jones                  Robert       A                Class 4
     Jones                  Robert       A                Class 3
     Jones                  Robert       A                Class 2
     Jones                  Robert       A                Class 1
    5 rows selected
    SQL>
Close Help