Previous Topic: LOOP StatementNext Topic: RAISE ERROR Statement


Example

A LOOP statement example follows. In the example that follows, logic that is not shown (for space considerations) is indicated by three vertically arranged periods.

     .
     .
     .
     DECLARE continue HANDLER FOR sqlexception, sqlwarning, not found
        GET stacked DIAGNOSTICS
           sqlStateLocal = RETURNED_SQLSTATE, errMsg = MESSAGE_TEXT;
     .
     .
     .
 loopExample:
    LOOP
       FETCH orderCrs INTO orderId, custId, creditReqAmt;
       IF sqlStateLocal <-> '00000' THEN
          LEAVE loopExample;
       END IF;
       .
       .
       .
    END LOOP loopExample DATACOM LOOPLIMIT 100;
    .
    .
    .