Skip to content

LOOP

DECLARE
i NUMBER;
BEGIN
FOR i IN 1..5 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
/
1
2
3
4
5

The provided code is an example of a basic loop in SQL that prints the numbers 1 through 5. The loop begins with the keyword FOR followed by the variable i in the range of 1 to 5 using the IN keyword. The loop processes each number in this range. Inside the loop, DBMS_OUTPUT.PUT_LINE(i) is used to print the current value of i. The loop ends with the END LOOP statement.