For Loop in Oracle Database 21c and before 21c

This is a quick comparison between the “For Loop” in oracle database 21c and pre Oracle 21c.

In Oracle Database 19c:

set serveroutput on
declare
i number(5,1);
begin
for i in 1 .. 5
loop
dbms_output.put_line (i);
end loop;
End;
/

In Oracle Database 21c:

set serveroutput on
begin
for i number(5,1) in 1 .. 6 by 2, reverse 7 .. 14 by 2, 15 .. 20 by 2
loop
dbms_output.put_line (i);
end loop;
End;
/

Notice that you can declare the variable “i” inline + you can specify a step value and multiple ranges.

Regards
Ahmed

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s