MOCKSTACKS
EN
Questions And Answers

More Tutorials









Oracle WHILE Loop


The WHILE loop is executed untill the condition of end is fulfilled. Simple example:

DECLARE
v_counter NUMBER(2); --declaration of counter variable
BEGIN
 v_counter := 0; --point of start, first value of our iteration
 WHILE v_counter < 10 LOOP --exit condition

 DBMS_OUTPUT.put_line('Current iteration of loop is ' || v_counter); --show current iteration
number in dbms script output
 v_counter := v_counter + 1; --incrementation of counter value, very important step
 END LOOP; --end of loop declaration
END;

This loop will be executed untill current value of variable v_counter will be less than ten.

The result:

CURRENT iteration OF LOOP IS 0
CURRENT iteration OF LOOP IS 1
CURRENT iteration OF LOOP IS 2
CURRENT iteration OF LOOP IS 3
CURRENT iteration OF LOOP IS 4
CURRENT iteration OF LOOP IS 5
CURRENT iteration OF LOOP IS 6
CURRENT iteration OF LOOP IS 7
CURRENT iteration OF LOOP IS 8
CURRENT iteration OF LOOP IS 9

The most important thing is, that our loop starts with '0' value, so first line of results is 'Current iteration of loop is 0'.

Conclusion

In this page (written and validated by ) you learned about Oracle WHILE Loop . What's Next? If you are interested in completing Oracle tutorial, your next topic will be learning about: Oracle Cursors.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.