Oracle PL/SQL - FOR loop with variable upper or lower bounds

Introduction

The upper or lower bounds of the FOR loop can be defined as variables or functions.

The following code will first round off the values into integers at runtime:

Demo

SQL>
SQL> declare-- from w  ww .  jav  a  2  s. c  o  m
  2       V_lower_nr NUMBER:=2/3;
  3  begin
  4       for main_c in reverse v_lower_nr..10/3
  5       loop
  6           DBMS_OUTPUT.put_line(main_c);
  7       end loop;
  8  end;
  9  /
3
2
1

PL/SQL procedure successfully completed.

SQL>

Related Topic