title: PL/SQL: ORA-00947: not enough values
body: <p>Im creating a procedure to display the n number of maximum and minimum salary for an employee. If i ll give 5 as input, the query will get me 5 maximum and minimum salary for an employee. </p>
  
  <p>For the above scenario, I have created an object with two columns like below</p>
  
  <pre><code>create type vrec as object(
  empno number,
  sal number
  );
  /
  </code></pre>
  
  <p>Then i created nested table with the help of object type, so that i can use the nested table as out parameter to return all the rows at one short.</p>
  
  <pre><code>create type vrec_type is table of vrec;
  /
  </code></pre>
  
  <p>After the data type creation, im creating a procedure like below</p>
  
  <pre><code>create or replace procedure pro_first_last(input in number,salary out vrec_type)
  is
  begin
  select empno,sal BULK COLLECT INTO salary from (
  select empno,sal from  
  (select empno,sal,rank() over(order by sal asc) min_sal from emp5 where sal is not null) where min_sal &lt;= 5
  union all
  select empno,sal from 
  (select empno,sal,rank() over(order by sal desc) max_sal from emp5 where sal is not null) where max_sal &lt;= 5);
  for i in salary.first..salary.last
  loop
  dbms_output.put_line(salary(i).empno);
  end loop;
  end;
  /
  </code></pre>
  
  <p>When i compiling the above procedure, im getting not enough values. I have also created the object with two columns and in select statement also im returning only two column. Could someone review and help me on this or provide some alternate solution.</p>