title: How to return a resultset / cursor from a Oracle PL/SQL anonymous block that executes Dynamic SQL?
body: <p>I have this table:</p>
  
  <pre><code>ALLITEMS
  ---------------
  ItemId  | Areas
  ---------------
  1       | EAST
  2       | EAST
  3       | SOUTH
  4       | WEST
  </code></pre>
  
  <p>The DDL:</p>
  
  <pre><code>drop table allitems;
  
  Create Table Allitems(ItemId Int,areas Varchar2(20));
  Insert Into Allitems(Itemid,Areas) Values(1,'east');
  Insert Into Allitems(ItemId,areas) Values(2,'east');
  insert into allitems(ItemId,areas) values(3,'south');
  insert into allitems(ItemId,areas) values(4,'east');
  </code></pre>
  
  <p>In MSSQL, to get a cursor from a dynamic SQL I can do:</p>
  
  <pre><code>DECLARE @v_sqlStatement VARCHAR(2000);
  SET @v_Sqlstatement = 'SELECT * FROM ALLITEMS';
  EXEC (@v_sqlStatement); --returns a resultset/cursor, just like calling SELECT 
  </code></pre>
  
  <p>In Oracle, I need to use a PL/SQL Block:</p>
  
  <pre><code>SET AUTOPRINT ON;
  DECLARE
   V_Sqlstatement Varchar2(2000);
   outputData SYS_REFCURSOR;
  BEGIN
   V_Sqlstatement := 'SELECT * FROM ALLITEMS';
   OPEN outputData for v_Sqlstatement; 
  End;
  --result is : anonymous block completed
  </code></pre>
  
  <p>**But all I get is </p>
  
  <blockquote>
    <p>anonymous block completed".</p>
  </blockquote>
  
  <p>How do I get it to return the cursor?</p>
  
  <p>(<em>I know that if I do AUTOPRINT, it will print out the information in the REFCURSOR (it's not printing in the code above, but thats another problem)</em>)</p>
  
  <p>I will be calling this Dynamic SQL from code (ODBC,C++), and I need it to return a cursor. How?</p>