Oracle PL/SQL - Reverse FOR LOOP Statements

Introduction

The FOR LOOP statement prints the numbers from 3 to 1.

Demo

SQL>
SQL>-- from   ww w  .  j  av a  2s  .  c  o m
SQL> BEGIN
  2    DBMS_OUTPUT.PUT_LINE ('upper_bound > lower_bound');
  3
  4    FOR i IN REVERSE 1..3 LOOP
  5      DBMS_OUTPUT.PUT_LINE (i);
  6    END LOOP;
  7
  8    DBMS_OUTPUT.PUT_LINE ('upper_bound = lower_bound');
  9
 10    FOR i IN REVERSE 2..2 LOOP
 11      DBMS_OUTPUT.PUT_LINE (i);
 12    END LOOP;
 13
 14    DBMS_OUTPUT.PUT_LINE ('upper_bound < lower_bound');
 15
 16    FOR i IN REVERSE 3..1 LOOP
 17      DBMS_OUTPUT.PUT_LINE (i);
 18    END LOOP;
 19  END;
 20  /
upper_bound > lower_bound
3
2
1
upper_bound = lower_bound
2
upper_bound < lower_bound

PL/SQL procedure successfully completed.

SQL>

Related Topic