Basic Oracle Concepts and Programming Question:
How To Use "WHILE" Statements in Oracle?
Answer:
If you have a block of codes to be executed repeatedly based a condition, you can use the "WHILE ... LOOP" statement. Here is a sample script on WHILE statements:
DECLARE
total NUMBER;
BEGIN
total := 0;
WHILE total < 10 LOOP
total := total+1;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Total counts: ' || TO_CHAR(total));
END;
This script should print this:
Total counts: 10
DECLARE
total NUMBER;
BEGIN
total := 0;
WHILE total < 10 LOOP
total := total+1;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Total counts: ' || TO_CHAR(total));
END;
This script should print this:
Total counts: 10
Previous Question | Next Question |
How To Use "IF" Statements on Multiple Conditions? | How To Use "FOR" Statements in Oracle? |