title: How to loop through columns with PL/SQL
body: <p>I have searched through and found only this problem:
  <a href="https://stackoverflow.com/questions/697367/loop-through-columns-sql">Loop through columns SQL</a>
  it's similar in some ways, but doesn't concern PL/SQL and Oracle Database, therefore I'm Asking new Question.</p>
  
  <p>I have a table with ca. 2000 rows and 600 columns. There are some columns comprised only NULLs in each row. What I want to do is to write a PL/SQL Procedure to remove those columns from the table.
  So I have met a problem, I wanted to loop through columns in PL/SQL with help of all_tab_columns view. You can see my code below (my table name is PreparedDocumentFeaturesValues):</p>
  
  <pre><code>PROCEDURE dropNullColumns AS
     l_query VARCHAR2(10000);
     all_row_count NUMBER;
     null_row_count NUMBER;
  BEGIN
     SELECT count(*) 
     INTO all_row_count 
     FROM PreparedDocumentFeaturesValues;
  
     FOR columnItem IN (SELECT column_name 
                        FROM all_tab_columns 
                        WHERE TABLE_NAME = UPPER('PreparedDocumentFeaturesValues'))
     LOOP
        SELECT count(*) 
        INTO null_row_count 
        FROM PreparedDocumentFeaturesValues 
        WHERE columnItem.column_name IS NULL;
  
        IF all_row_count=null_row_count THEN 
           l_query := 'ALTER TABLE PreparedDocumentFeaturesValues DROP COLUMN ' || columnItem.column_name;
           EXECUTE IMMEDIATE l_query;
        END IF;
     END LOOP;
  END;
  </code></pre>
  
  <p>The problem is that statement:</p>
  
  <pre><code>SELECT count(*) 
  INTO null_row_count 
  FROM PreparedDocumentFeaturesValues 
  WHERE columnItem.column_name IS NULL;
  </code></pre>
  
  <p>has character type as a column_name and null_row_count always equals 0.</p>
  
  <p>I'm pretty sure, here is somebody who know how can I cope with this problem (by improving the code above, or maybe is there any other way to do such a thing?>
  Thank you in advance for your help.</p>