Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Programming Using Oracle 11g

Similar presentations


Presentation on theme: "Database Programming Using Oracle 11g"— Presentation transcript:

1 Database Programming Using Oracle 11g
Iterative Control-II

2 Iterative Control-II Iterative Control-II: Continue Statement
Conditionally Exit from current iteration of loop Statements after continue are skipped Control is transfer to next iteration Must be inside loop

3 Iterative Control-II Implementing Continue Statement with Basic Loop

4 Iterative Control-II DECLARE x NUMBER := 0; BEGIN LOOP
DBMS_OUTPUT.PUT_LINE ('Inside loop: x = ' || TO_CHAR(x)); x := x + 1; IF x < 3 THEN CONTINUE; END IF;

5 Iterative Control-II DBMS_OUTPUT.PUT_LINE ('Inside loop, after CONTINUE: x = ' || TO_CHAR(x)); EXIT WHEN x = 5; END LOOP; DBMS_OUTPUT.PUT_LINE (' After loop: x = ' || TO_CHAR(x)); END;

6 Iterative Control-II Continue When Statement
Unconditionally Exit from current iteration of loop Statements after continue are skipped Control is transfer to next iteration Must be inside loop

7 Iterative Control-II Implementing Continue WHEN with Loop

8 Iterative Control-II DECLARE x NUMBER := 0; BEGIN LOOP
DBMS_OUTPUT.PUT_LINE ('Inside loop: x = ' || TO_CHAR(x)); x := x + 1; CONTINUE WHEN x < 3;

9 Iterative Control-II DBMS_OUTPUT.PUT_LINE
('Inside loop, after CONTINUE: x = ' || TO_CHAR(x)); EXIT WHEN x = 5; END LOOP; DBMS_OUTPUT.PUT_LINE (' After loop: x = ' || TO_CHAR(x)); END;

10 Iterative Control-II Implementing Continue WHEN with For Loop

11 Iterative Control-II declare val number(3):=3; BEGIN
FOR i IN LOOP dbms_output.put_line('i=' || TO_CHAR(i)); CONTINUE WHEN (i+1) = val; dbms_output.put_line('Did not jump to the top of the loop'); END LOOP; END;

12 Iterative Control-II Nested Loops Loop within loop
Any type of loop can be nested within any other or same type of loop Again one iteration of main loop complete inner loop is executed

13 Iterative Control-II Syntax for Nested Loops

14 Iterative Control-II LOOP – Main Loop Sequence of statements1
LOOP – Nested or inner loop Sequence of statements2 END LOOP; END

15 Iterative Control-II Implementing Nested Loops-I

16 Iterative Control-II BEGIN FOR v_outerloopcounter IN 1..2 LOOP
FOR v_innerloopcounter IN 1..4 DBMS_OUTPUT.PUT_LINE('Outer Loop counter is ' || v_outerloopcounter || ' Inner Loop counter is ' || v_innerloopcounter); END LOOP; END LOOP; END;

17 Iterative Control-II Implementing Nested Loops-II

18 Iterative Control-II DECLARE v_counter1 INTEGER:=0;
BEGIN WHILE v_counter1 < 3 LOOP DBMS_OUTPUT.PUT_LINE('v_counter1 : ' || v_counter1); LOOP DBMS_OUTPUT.PUT_LINE('v_counter2: ' || v_counter2);

19 Iterative Control-II v_counter2 := v_counter2 + 1;
EXIT WHEN v_counter2 >= 2; END LOOP; v_counter1 := v_counter1+1; END;


Download ppt "Database Programming Using Oracle 11g"

Similar presentations


Ads by Google