title: PLSQL: How to create a cursor using a variable as table_name
body: <p>I'm trying the following in PLSQL:</p>
  
  <ul>
  <li><p>I have a table who contain a list of table names, something like:   Table_1, Table_2, Table_3, etc...</p></li>
  <li><p>I rewrite that table on a daily basis, so the list of tables is dynamic, one day you might get 3 tables, tomorrow 7 tables and so on.</p></li>
  <li><p>Based on that list of tables, i want to export the content of those tables using the UTL_FILE.</p></li>
  </ul>
  
  <p>So far, i tried to fetch the table names into a variable and then loop over the variable, but it doesn't work.</p>
  
  <p>I have the following codes:</p>
  
  <pre><code>Declare
      var1 SYS_REFCURSOR;
      var2 varchar2(20);
      var3 varchar2(20);    
      ARCHIVE UTL_FILE.FILE_TYPE;
      Cursor cur2 IS SELECT TABLE_NAME FROM LIST_OF_TABLES; 
  
  BEGIN   
  
  ARCHIVO:=UTL_FILE.FOPEN('test_path','test.txt','W');
  
          for i in cur2 loop
  
          var2:= i.table_name;
  
          OPEN var1 for 'SELECT SKUID, CMRPRICE FROM '||VAR2;
          loop
  
         FOR C IN MICURSOR LOOP
    UTL_FILE.PUT_LINE(ARCHIVE,(''||C.SKUID||''||','||''||  C.CMRPRICE||''));
        END LOOP;
        UTL_FILE.FCLOSE(ARCHIVE);
          close var1;
          end loop;
  
  END;
  </code></pre>
  
  <p>i expect to obtain the same amount of files as tables on the table list</p>
  
  <p>Thanks in advance</p>