PLSQL/ How to add values during iteration of associative array

FireVortex picture FireVortex · Sep 14, 2012 · Viewed 20.8k times · Source

i need something like this in procedure PLSQL

 arrayCount:=parArray.Count;
 For i In 1 .. arrayCount Loop
    lsPar(i):=parArray(i);
 End Loop;

is it possible? Thx for advice! :)

Answer

Gaurav Soni picture Gaurav Soni · Sep 14, 2012

If you're working on oracle ,then this piece of anonymous block will work for you

 declare
    TYPE parArray IS TABLE OF VARCHAR2(64) index by binary_integer;
    v_parArray parArray;
    arrayCount number;
    lsPar parArray;

    begin
    v_parArray(1):='A';
    v_parArray(2):='B';
    v_parArray(3):='C';

    arrayCount:=v_parArray.Count;
       For i In 1 .. arrayCount 
       Loop
          lsPar(i):=v_parArray(i);
       End Loop;

     arrayCount:=lsPar.Count;
        For i In 1 .. arrayCount
         Loop
          dbms_output.put_line('The value of Ispar at index '||i||' is '||lsPar(i));
        End Loop;
     end;  

Output

 The value of Ispar at index 1 is A
 The value of Ispar at index 2 is B
 The value of Ispar at index 3 is C