title: How to use index by table collections in PL/SQL
body: <p>I am a new user to PL/SQL and recently created an account in Stack Overflow. I am trying to use one loop to retrieve data and store it in an index by table, and then another loop to display the data from the index by table, but it keeps giving me an error that the data is not found. Here is my code:</p>
  <pre class="lang-sql prettyprint-override"><code>    SET SERVEROUTPUT ON
      DECLARE
        TYPE dept_table_type IS TABLE OF departments.department_name%TYPE INDEX BY PLS_INTEGER;
        my_dept_table dept_table_type;
        loop_count NUMBER := 10;
        deptno NUMBER := 10;
      BEGIN
        dbms_output.put_line('DEPARTMENT_ID                  DEPARTMENT_NAME');
        LOOP
          SELECT department_name INTO my_dept_table(loop_count)
          FROM departments
          WHERE department_id = deptno;
  
          deptno := deptno + 10;
          loop_count := loop_count + 10;
  
          EXIT WHEN loop_count &gt; 100;
        END LOOP;
  
        FOR I in my_dept_table.FIRST..my_dept_table.LAST
        LOOP
          DBMS_OUTPUT.PUT_LINE(I||'                                   '||my_dept_table(I));
        END LOOP;
      END;
      /
  
  
      Result: Error report -
      ORA-01403: no data found
      ORA-06512: at line 18
      01403. 00000 -  &quot;no data found&quot;
      *Cause:    No data was found from the objects.
      *Action:   There was no data from the objects which may be due to end of fetch.
  </code></pre>
  <p>Can anyone please check the code. I am a new user to PLSQL and Thank you.</p>