New PL/SQL Feature in Oracle 11g: CONTINUE

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

4 thoughts on “New PL/SQL Feature in Oracle 11g: CONTINUE

  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

Comments are closed.

Next Post

Sharing only the APPL_TOP in 11.5.10

Facebook0TwitterLinkedinIn the past days I have implemented a well known architecture to many of my fellow Oracle E-Business Suite DBAs: An architecture that consists of multiple Application Servers. Until version 11.5.10, the common practice was to share the APPL_TOP between multiple Application Servers, and from 11.5.10 onwards Oracle started supporting […]