Previous Topic: LEAVE StatementNext Topic: LOOP Statement


Example

A LEAVE statement example follows. This example exits the loop after a non-zero SQLSTATE. 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;
    .
    .
    .