Oracle PL/SQL - CONTINUE WHEN Statement in Inner FOR LOOP Statement

Description

CONTINUE WHEN Statement in Inner FOR LOOP Statement

Demo

SQL>
SQL> drop TABLE emp;

Table dropped.--  w w  w  .j a va2s . c o m

SQL>
SQL> CREATE TABLE emp(
  2  empid NUMBER(6),
  3  first_name VARCHAR2(20),
  4  last_name VARCHAR2(25)) ;
SQL>
SQL> INSERT INTO emp VALUES( 100, 'Steven', 'King');
SQL> INSERT INTO emp VALUES( 101, 'Mary', 'Smith');
SQL>
SQL>
SQL> DECLARE
  2    v_emp emp%ROWTYPE;
  3    CURSOR c1 is SELECT * FROM emp;
  4  BEGIN
  5    OPEN c1;
  6    -- Fetch entire row into v_emp record:
  7    <<outer_loop>>
  8    FOR i IN 1..10 LOOP
  9      -- Process data here
 10      FOR j IN 1..10 LOOP
 11        FETCH c1 INTO v_emp;
 12        CONTINUE outer_loop WHEN c1%NOTFOUND;
 13        -- Process data here
 14      END LOOP;
 15    END LOOP outer_loop;
 16
 17    CLOSE c1;
 18  END;
 19  /

PL/SQL procedure successfully completed.

SQL>

Related Topic