title: PLS-00487 Error-Invalid reference to Variable 'CHAR'
body: <p>I'm designing a function that is part of a larger package. The function is intended to take a District Code and return a collection of unique IDs for 10-15 stores that are assigned to that district. The function is intended to return a collection that can be queried like a table, i.e., using the TABLE function in a SQL statement. </p>
  
  <p>I've created the following Types:</p>
  
  <p>Schema Level type:</p>
  
  <pre><code>create or replace TYPE HDT_CORE_ORGIDS AS TABLE OF CHAR(20);
  </code></pre>
  
  <p>and a Type inside the Package</p>
  
  <pre><code>TYPE CORE_ORGIDS IS TABLE OF CHAR(20) INDEX BY BINARY_INTEGER;
  </code></pre>
  
  <p>Here's the function code:</p>
  
  <pre><code>     FUNCTION FindDistrictOrgs(
             ParamOrgCode VARCHAR2
        )
        RETURN HDT_CORE_ORGIDS
        AS
             ReturnOrgs HDT_CORE_ORGIDS := HDT_CORE_ORGIDS();
             FDOTemp HDT_CORE_MAIN.CORE_ORGIDS; 
             i BINARY_INTEGER := 0;
  
             CURSOR FDOCurr IS
                  SELECT org.id AS OrgID
                       FROM tp2.tpt_company org
                       WHERE LEVEL = 2
                       START WITH org.name = ParamOrgCode
                       CONNECT BY PRIOR org.id = org.parent_id;
  
        BEGIN
             OPEN FDOCurr;
                  LOOP
                       i := i +1;
                       FETCH FDOCurr INTO FDOTemp(i);
                       EXIT WHEN FDOCurr%NOTFOUND;
                  END LOOP;
             IF FDOTemp.EXISTS(FDOTemp.FIRST) THEN
                  ReturnOrgs.EXTEND(FDOTemp.LAST);
                  FOR x IN FDOTemp.FIRST .. FDOTemp.LAST LOOP
                       ReturnOrgs(x) := FDOTemp(x).OrgID;
                  END LOOP;
             END IF; 
             CLOSE FDOCurr;
             RETURN ReturnOrgs;         
  
   END FindDistrictOrgs ;
  </code></pre>
  
  <p>I'm getting the <code>PLS-00487:Invalid Reference to variable 'CHAR'</code> at the line:</p>
  
  <pre><code>                         ReturnOrgs(x) := FDOTemp(x).OrgID;
  </code></pre>
  
  <p>I've double-checked at the value returned by the SQL (the <code>org.id AS OrgID</code>) is of the <code>CHAR(20 BYTE)</code> datatype. </p>
  
  <p>So...what's causing the error?</p>
  
  <p>Any help is appreciated! :)</p>