title: Using PLSQL variables in SQL Query based on FOR LOOP
body: <p>I'm trying to execute some <code>DML</code> queries with <code>PLSQL</code>. I've declare an array having 5 table names and I want to run it under <code>FOR LOOP</code>. In this moment my code looks like:</p>
  <pre><code>DECLARE
    c_exist NUMBER;
    test_array dbms_sql.varchar2_table; 
  BEGIN 
   test_array(1) := 'TEST_1';
   test_array(2) := 'TEST_2';
  FOR i IN test_array.FIRST .. test_array.LAST
   LOOP
    SELECT count(*) INTO c_exist from user_tables WHERE table_name = test_array(i); 
    IF c_exist = 1 THEN 
     EXECUTE IMEDIATE 'ALTER TABLE ' || test_array(i) || 'COMPRESS'; 
    END IF; 
   END LOOP; 
  END;
  </code></pre>
  <p>The problem is when script is trying to read <code>test_array</code> variable under <code>SELECT</code> statement. I'm getting an <code>ORA-06512 ERROR</code>. In my opinion script syntax is good. It passed test without <code>SELECT</code> stamtent, but with simply used <code>dbms_output.put_line(test_array(i))</code> it passed well.</p>
  <p>Whole error stack:</p>
  <pre><code>ORA-06502: 
  ORA-06512: 
  06502. 00000 -  &quot;PL/SQL: numeric or value error%s&quot;
  *Cause:    An arithmetic, numeric, string, conversion, or constraint error
             occurred. For example, this error occurs if an attempt is made to
             assign the value NULL to a variable declared NOT NULL, or if an
             attempt is made to assign an integer larger than 99 to a variable
             declared NUMBER(2).
  *Action:   Change the data, how it is manipulated, or how it is declared so
             that values do not violate constraints.
  </code></pre>
  <p>Additionaly, something like that works perfectly, and dbms_output printing correctly:</p>
  <pre><code>DECLARE
    c_exist NUMBER;
    test_array dbms_sql.varchar2_table; 
  BEGIN 
   test_array(1) := 'TEST_1';
   test_array(2) := 'TEST_2';
  FOR i IN test_array.FIRST .. test_array.LAST
   LOOP
    dbms_output.put_line(test_array(i)); 
   END LOOP; 
  END;
  </code></pre>