Nested loops and labels
0Nested loops and labels:
- Loops can be nested to multiple levels.
All the loops can be nested into one another. - Loops can be labelled as per the requirements.
- Label loops by placing the label before the word loop within the label delimiters.
- When the loop is labelled, the label name can be optionally included after the END LOOP statement for clarity.
SQL>DECLARE
v_num NUMBER:=1;
BEGIN
<<outerloop>> LOOP
<<innerloop>> LOOP
EXIT WHEN v_num>5;
Display(‘Inner loop:’||v_num);
v_num:=v_num+1;
END LOOP innerloop;
Display(‘Outer loop:’||v_num);
v_num:=v_num+1;
EXIT WHEN v_num>10;
END LOOP outerloop;
END;
0 comments: