title: Oracle-PL/SQL Functions with return type nested table Error Type is incomplete or malformed
body: <pre><code>CREATE TYPE dname AS OBJECT
  (
    depno      NUMBER,
    cnt_dname  NUMBER
  );
  /
  
  CREATE TYPE nt_dname_dname AS TABLE of dname;
  /
  
  CREATE OR REPLACE FUNCTION f1 RETURN nt_dname 
  AS    
      nt_dname        t_d     := t_d();
      n               NUMBER  := 0;
  BEGIN
      FOR x IN 
      (
          SELECT  department_id, count(employee_id)
          FROM    employees
          GROUP BY department_id
      )
      LOOP
          nt_dname.EXTEND;
          n               := n+1;
          nt_dname(n)     := dname(x.depno,x.cnt_dname);
      END LOOP; 
  
      RETURN t_d;
  END;
  /   
  </code></pre>
  
  <p>I'm getting the following error message </p>
  
  <pre><code>Error: PL/SQL: Compilation unit analysis terminated
  Error(1,20): **PLS-00320: the declaration of the type of this expression is 
  incomplete or malformed**
  </code></pre>
  
  <p>Kindly suggest where it is wrong. I'm trying to get 
  count of employees in each department and giving it as output (<strong>RETURN</strong> <em>nested_table</em>).</p>