title: Building a String Array in Pl/SQL For loop
body: <p>Hello I have an array of strings (CompTblNameArry) that I want to contain certain usernames in database based on select query within cursor.</p>
  
  <p>Code is shown below:</p>
  
  <pre><code>DECLARE
    TYPE SegTblTyp IS TABLE OF mto_kgpr.pdtable_12%rowtype;
    TYPE TblNameStringArry IS TABLE OF varchar2(61) INDEX BY PLS_INTEGER;
    --Type TblNameStringArry is varray(100) of varchar2(61);
    LoopIteration pls_integer;
  
    CURSOR GetUserNamesCursor is
    SELECT username FROM DBA_USERS WHERE USERNAME LIKE 'MTO_K%';
  
    SegCollectionTbl SegTblTyp;
    --CompTblNameArry CompTblNameArryTyp;
    CompTblNameArry TblNameStringArry;
  
      BEGIN
         LoopIteration := 1;
  
          FOR Username in GetUserNamesCursor
          LOOP
            DBMS_OUTPUT.PUT_LINE('Iteration: ' || LoopIteration || ' username ' || Username.Username);
            -- Row Below is causing Error
            --CompTblNameArry(i) = Username.Username;
            LoopIteration := LoopIteration + 1;
  
          END LOOP;
      END;
  </code></pre>
  
  <p>What is proper syntax for populating the CompTblNameArry?  The method that I am trying is not working:</p>
  
  <p>CompTblNameArry(i) = Username.Username;</p>
  
  <p>Thanks,
  Pat</p>