Mega Code Archive

 
Categories / Oracle PLSQL / PL SQL
 

Assign the first character index to a variable

SQL> SQL> DECLARE   2    current VARCHAR2(9 CHAR);   3    element INTEGER;   4   5    TYPE months_varray IS VARRAY(12) OF STRING(9 CHAR);   6    TYPE calendar_table IS TABLE OF VARCHAR2(9 CHAR) INDEX BY VARCHAR2(9 CHAR);   7   8    month MONTHS_VARRAY := months_varray('January','February','March','April','May','June','July','August','September','October','November','December');   9  10    calendar CALENDAR_TABLE;  11  BEGIN  12    IF calendar.COUNT = 0 THEN  13      FOR i IN month.FIRST..month.LAST LOOP  14        calendar(month(i)) := TO_CHAR(i);  15        DBMS_OUTPUT.PUT_LINE('Index ['||month(i)||'] is ['||i||']');  16      END LOOP;  17  18  19    END IF;  20  END;  21  / Index [January] is [1] Index [February] is [2] Index [March] is [3] Index [April] is [4] Index [May] is [5] Index [June] is [6] Index [July] is [7] Index [August] is [8] Index [September] is [9] Index [October] is [10] Index [November] is [11] Index [December] is [12] PL/SQL procedure successfully completed.