Please disable your adblock and script blockers to view this page

Search this blog

Friday 23 March 2018

PL/SQL For Loop


PL/SQL FOR loop is used when we need to execute set of statements for the specific number of times and loop operates between the start and end counter values. The counter is always incremented by one and once the counter reaches to end integer value, the loop terminates

The syntax of PL/SQL FOR Loop is like this

FOR counter_variable IN start value.. end value LOOP

statements to execute 

END LOOP;



Look at this example of PL/SQL FOR Loop


BEGIN
-- FOR Loop syntax and counter values
FOR i IN 1..9 LOOP
dbms_output.put_line('Value of- '||i);
END LOOP;
END;

and output is


REVERSE FOR Loop Example

We can reverse iteration of FOR loop using REVERSE keyword


BEGIN
-- FOR Loop syntax and counter values
FOR i IN REVERSE 1..9 LOOP
dbms_output.put_line('Value of- '||i);
END LOOP;
END;

and output is


Cheers :) Happy Learning

No comments :

Post a Comment