title: Oracle SQl Populating a cursor in a procedure from a sql statement saved in a table field
body: <p>We want to populate a cursor in a procedure that is populated from a select statement in a table.</p>
  
  <p>We created a table named stored_sql_statments  with 2 columns, Created_date &amp; Sql_statement.
  In that table we will insert a select statement that selects other data from the database based on the clients needs.
  Example:
      insert into  stored_sql_statments 
                (  Created_date , Sql_statement)
      values('2/1/2011', 'Select Client_idn , something_neat  from cool_table where animal = 'dog' ')</p>
  
  <p>Then in the procedure we have a bunch of code that does what it needs to do, which will never change, but the select statement we have in the cursor changes periodically.  We always need to return 2 fields but the rest of the select statement changes.</p>
  
  <p>So now we need to populate the cursor in the procedure with what the select statement coming form the table.
  If it was returning only 1 row we have: 
      declare
      x  varchar2(600);
      rec1 number(10);
      rec2 varchar2(15);
      begin
      execute immediate select Sql_statement into x from stored_sql_statments where  created_date = '2/1/2011';
      execute immediate x into rec1, rec2;
      ...</p>
  
  <p>This works, but we don't need it to go into 2 variables we need it to go into a cursor. The real select statement (the above code is just a simple example of what we need to do) is bringing back thousands of records so we need to use a cursor.</p>
  
  <p>Hope this all makes sense</p>
  
  <p>So if anyone knows how to do this, it would be appreciated.</p>