Change while loop counter : While Loop « PL SQL « Oracle PL / SQL






Change while loop counter

   

SQL> set serverout on;
SQL> -- while loop
SQL>
SQL>  declare
  2      loops number := 0;
  3    begin
  4      dbms_output.put_line('Before my loop');
  5
  6      while loops < 5 loop
  7        dbms_output.put_line('Looped ' || loops || ' times');
  8        loops := loops + 1;
  9      end loop;
 10
 11      dbms_output.put_line('After my loop');
 12    end;
 13    /
Before my loop
Looped 0 times
Looped 1 times
Looped 2 times
Looped 3 times
Looped 4 times
After my loop

PL/SQL procedure successfully completed.

SQL>
           
         
    
    
  








Related examples in the same category

1.Put two statement in while loop
2.Example of a WHILE loop that never executes
3.Corrected WHILE loop that executes
4.While Loop with condition
5.While loop with complex conditions
6.Insert value in while loop
7.Do calculation with while loop counter
8.Call EXIT to jump out of a while loop
9.Use EXIT WHEN to exit a while loop
10.WHILE..LOOP, Cursor Loop
11.WHILE Loop: This condition will evaluate to NULL, since v_Counter is initialized to NULL by default
12.WHILE Loop: Test the loop counter before each loop iteration to insure that it is still less than 50
13.WHILE Loop
14.This script demonstrates variable visibility
15.The WHILE loop uses a loop index value as its gate on entry criterion:
16.While loop and number counter