Use PLS_INTEGER as the loop counter : PLS_INTEGER « PL SQL Data Types « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> DECLARE
  2     lv_counter_num       PLS_INTEGER := 0;
  3     lv_total_counter_num PLS_INTEGER := 0;
  4  BEGIN
  5     LOOP
  6        lv_counter_num       := lv_counter_num + 1;
  7        IF lv_counter_num >= 100000 THEN
  8           DBMS_OUTPUT.PUT_LINE('Processed 100,000 Records. Total ' ||'Processed ' || lv_total_counter_num);
  9           lv_total_counter_num := lv_total_counter_num +
 10              lv_counter_num;
 11           lv_counter_num := 0;
 12           EXIT WHEN lv_total_counter_num >= 1000000;
 13        END IF;
 14     END LOOP;
 15  END;
 16  /
Processed 100,000 Records. Total Processed 0
Processed 100,000 Records. Total Processed 100000
Processed 100,000 Records. Total Processed 200000
Processed 100,000 Records. Total Processed 300000
Processed 100,000 Records. Total Processed 400000
Processed 100,000 Records. Total Processed 500000
Processed 100,000 Records. Total Processed 600000
Processed 100,000 Records. Total Processed 700000
Processed 100,000 Records. Total Processed 800000
Processed 100,000 Records. Total Processed 900000

PL/SQL procedure successfully completed.

SQL>








21.19.PLS_INTEGER
21.19.1.PLS_INTEGER
21.19.2.PLS_INTEGER in action
21.19.3.Use PLS_INTEGER as the loop counter