Mega Code Archive

 
Categories / Oracle PLSQL / PL SQL
 

Use variable as an upper bound of for loop

SQL> SQL> SQL> -- Uses an upper bound: SQL> SQL> SET SERVEROUTPUT ON SQL> DECLARE   2    upper INTEGER := 5;   3  BEGIN   4    FOR i IN 1..upper LOOP   5      DBMS_OUTPUT.PUT_LINE('This has executed' ||TO_CHAR(i)||' time(s)');   6    END LOOP;   7  END;   8  / This has executed1 time(s) This has executed2 time(s) This has executed3 time(s) This has executed4 time(s) This has executed5 time(s) PL/SQL procedure successfully completed. SQL> SQL>