title: Fetching Table Data with Cursor to a Varray in oracle database
body: <p>I have a table called PhoneBook with this attributes: ID, FirstName, LastName. and it has 5 records
  I Want to create an VARRAY and fetch all firstNames in the PhoneBook Table into the VARRAY using Cursor. Here is my code:</p>
  
  <pre><code>DECLARE
      v_FirstName PHONEBOOK.FIRSTNAME%TYPE;
      TYPE arrayNames IS VARRAY(10) OF VARCHAR2(20);
      v1 arrayNames;
      i INT := 0;
      CURSOR c_phonebook IS SELECT FIRSTNAME FROM PHONEBOOK;
         BEGIN
             v1 := arrayNames(); 
             OPEN c_phonebook;
             LOOP
                  FETCH c_phonebook INTO v_firstname;
                  v1(i) := v_firstname;
                  i := i+1;
                  EXIT WHEN c_phonebook%NOTFOUND;
             END LOOP;
  
            CLOSE c_phonebook;
  
         END;/
  </code></pre>
  
  <p>When I Compile this code it gave me an error:</p>
  
  <blockquote>
    <p>ORA-06532: Subscript outside of limit
    ORA-06512: at line 14
    06532. 00000 -  "Subscript outside of limit"
    *Cause:    A subscript was greater than the limit of a varray
               or non-positive for a varray or nested table.
    *Action:   Check the program logic and increase the varray limit
               if necessary.</p>
  </blockquote>
  
  <p>Please help me to solve this problem. thank you</p>