New PL/SQL Feature in Oracle 11g: CONTINUE

4

A minor new PL/SQL feature in Oracle 11g is the new statement ‘continue’.  With the continue statement you can skip to the next iteration in a loop. A small example:

begin
  for i in 1..3
  loop
    dbms_output.put_line('i='||to_char(i));
    if ( i = 2 )
    then
      continue;
    end if;
    dbms_output.put_line('Only if i is not equal to 2');
  end loop;
end;

SQL> i=1
Only if i is not equal to 2
i=2
i=3
Only if i is not equal to 2

PL/SQL-procedure is geslaagd.

Or you can use ....
the ‘continue when’ statement to determine when to go to the next iteration in the loop.

begin
  for i in 1..3
  loop
    dbms_output.put_line('i='||to_char(i));
    continue when ( i = 2 );
    dbms_output.put_line('Only if i is not equal to 2');
  end loop;
end;

SQL> i=1
Only if i is not equal to 2
i=2
i=3
Only if i is not equal to 2

Share.

About Author

4 Comments

  1. That’s great. PL/SQL looks more and more like a real procedure language now. I started programming with PL/SQL in Oracle 7.1 since 1997. It takes a long long time for Oracle PL/SQL to reach the current perfectness. :-)

    Hope to share knowledge and experience with Oracle guys.

  2. Cool, beats the goto and exception options as well…. although it is a similar construct to goto so bound to be a trap for young players ;-)

  3. That’s a nice little enhancement for PL/SQL, because currently you have to use sometimes long IF statements just to skip processing in this iteration.

    Patrick

  4. It is good to see how PL/SQL keeps evolving, borrowing nice functionality and useful constructs from other languages. Thanks for sharing this info. Looking forward to start working with 11g for real! regards,
    Lucas