title: Is there any possibility of creating view or table based on the output of a dynamically opened ref cursor?
body: <p>I have learnt how to return a dynamically opened ref cursor. Now based on the output, I want to create a table or a view.</p>
  
  <p>Input table:</p>
  
  <pre><code>   create table sales
      (s_sale_name varchar2(20),
      s_date_sal date,
      s_qty number(10)
      );
  </code></pre>
  
  <p>Records</p>
  
  <pre><code>insert into sales values ('Norb','10-MAR-2019',10000);
  insert into sales values ('Bert','10-MAR-2019',5000);
  insert into sales values ('Alba','10-MAR-2019',4000);
  insert into sales values ('Rob','10-MAR-2019',200000);
  insert into sales values ('Norb','11-MAR-2019',5000);
  insert into sales values ('Bert','11-MAR-2019',13000);
  insert into sales values ('Rob','11-MAR-2019',80000);
  insert into sales values ('Norb','12-MAR-2019',1000);
  insert into sales values ('Bert','12-MAR-2019',4000);
  insert into sales values ('Rob','12-MAR-2019',40000);
  insert into sales values ('Alba','12-MAR-2019',2000);
  </code></pre>
  
  <p>Query output</p>
  
  <pre><code>sales_name 10-MAR-2019 11-MAR-2019 12-MAR-2019 
  Norb             10000        5000        1000
  Bert              5000       13000        4000 
  Alba              4000           0        2000 
  Rob             200000       80000       40000
  </code></pre>
  
  <p>Now the result should be saved in a table or a view. I have learnt how to return a dynamically opened ref cursor so far.</p>
  
  <p>------Here is the procedure I used -----------</p>
  
  <pre><code>create or replace package p_sales_pkg 
  as 
  type rc is ref cursor;
  procedure get_query( p_cursor in out rc, p_start date, p_end date );
  end;
  /
  
  create or replace package body p_sales_pkg
  as
   procedure get_query( p_cursor in out rc, p_start date, p_end date )
   is
   l_query long := 'select s_name ';
   begin
    for i in 1 .. trunc(p_end)-trunc(p_start)+1
   loop
   l_query := l_query || ', sum( decode( trunc(s_date), ' ||
   'to_date( ''' || to_char(p_start+i-1,'yyyymmdd') ||
   ''', ''yyyymmdd'' ), s_qty, 0 )) "' ||
   to_char(p_start+i-1) || '"';
   end loop;
  l_query := l_query || ' from sales group by s_name';
   open p_cursor for l_query;
   end;
   end;
   /
  
  set autoprint on
  
  
  
  var x refcursor
  
  exec nw_demo_pkg.get_query( :x, '10-MAR-19', '13-MAR-19' );
  </code></pre>