9th Example - LOOP on PL/SQL



Besides being able to perform the selection operation / condition, PL/SQL is able to perform operations iteration / looping. There are 3 looping operator can be used in PL/SQL, the LOOP, FOR and WHILE. The following example uses LOOP operator for looping:

DECLARE
  jml NUMBER:=0;
BEGIN
  LOOP   
    jml := jml + 1;
    DBMS_OUTPUT.PUT_LINE(jml);
    EXIT WHEN jml=10;
  END LOOP;
END;
/

Above PL/SQL block will do looping 10 times looping. 10 counting many times will the held by JML variable. The resulting output is a number from 1 to 10.

No comments

Powered by Blogger.