Skip to content

FOR

DECLARE
message VARCHAR2(1000);
BEGIN
FOR i IN 1..5 LOOP
message := message || i || ' ';
END LOOP;
DBMS_OUTPUT.PUT_LINE (message);
END;
1 2 3 4 5

The FOR loop statement provides a convenient mechanism for executing SQL statements multiple times. In the above example, a FOR loop runs from 1 to 5, each time concatenating the loop index to a message string. The message string is then output to the console after the loop has finished executing, resulting in the output 1 2 3 4 5.