title: oracle sql: collect aggregation
body: <p>I want to group my database entries by an attribute and to know which entries are in each group at the same time. I collect the ids of the grouped entries with Oracle COLLECT function <a href="https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions024.htm#SQLRF06304" rel="nofollow noreferrer">COLLECT Function</a></p>
  
  <pre><code>DECLARE
    TYPE ids_type IS TABLE OF number(19, 0);   
    ids ids_type;
  BEGIN 
    select cast(collect(r.id) as ids_type) into ids from rechnungsdaten r group by r.status;
  END;
  </code></pre>
  
  <p>But then I get the error:</p>
  
  <blockquote>
    <p>Error report - <br> ORA-06550: Line 5, Column 44:<br> PL/SQL:
    ORA-00902: Invalid datatype<br> ORA-06550: Line 5, Column 5:<br>
    PL/SQL: SQL Statement ignored<br>
    06550. 00000 -  "line %s, column %s:\n%s"<br>
    *Cause:    Usually a PL/SQL compilation error.<br>
    *Action:</p>
  </blockquote>
  
  <p>What is wrong here?</p>