FIRST, LAST, NEXT, and PRIOR. : Table of Char « PL SQL « Oracle PL / SQL






FIRST, LAST, NEXT, and PRIOR.

  
SQL>
SQL> set serveroutput on
SQL>
SQL> DECLARE
  2    TYPE CharTab IS TABLE OF CHAR(1);
  3    v_Characters CharTab :=
  4      CharTab('M', 'a', 'd', 'a', 'm', ',', ' ', 'I', '''', 'm', ' ', 'A', 'd', 'a', 'm');
  5
  6    v_Index INTEGER;
  7  BEGIN
  8    v_Index := v_Characters.FIRST;
  9    WHILE v_Index <= v_Characters.LAST LOOP
 10      DBMS_OUTPUT.PUT(v_Characters(v_Index));
 11      v_Index := v_Characters.NEXT(v_Index);
 12    END LOOP;
 13    DBMS_OUTPUT.NEW_LINE;
 14
 15    v_Index := v_Characters.LAST;
 16    WHILE v_Index >= v_Characters.FIRST LOOP
 17      DBMS_OUTPUT.PUT(v_Characters(v_Index));
 18      v_Index := v_Characters.PRIOR(v_Index);
 19    END LOOP;
 20    DBMS_OUTPUT.NEW_LINE;
 21  END;
 22  /
Madam, I'm Adam
madA m'I ,madaM

PL/SQL procedure successfully completed.

SQL>
SQL>

   
  








Related examples in the same category

1.Use table of char as an array
2.Loop backwards over the table
3.Check if next index value exists.
4.Print an indexed element from the array.