title: Executing a table of dynamic SQL statements
body: <p>I built a script using SQL Server that went through each table in a database and built a dynamic statement that when executed, displayed the column name, type, number of filled values, and total row for each column. </p>
  
  <p>I am now trying to build the same thing with Oracle but I am running into problems. The following code gets me a table that is filled with all of the appropriate statements, but how can I execute and display them?</p>
  
  <pre><code>&gt;SELECT
      'SELECT ''' || atc.column_name || ''', ''' || atc.table_name || ''', ''' ||     atc.data_type || ''', 
  SUM(CASE WHEN temp.'|| atc.column_name || ' IS NULL THEN 0 ELSE 1 END)  "Filled     Values", 
      COUNT(temp.' || atc.column_name || ') "Total Records" 
      FROM all_tab_columns atc 
      JOIN '|| atc.table_name || ' temp ON atc.column_name = ''' || 
      atc.column_name ||''' AND atc.table_name = ''' || atc.table_name || '''' AS SQLRow 
  FROM all_tab_columns atc;
  </code></pre>
  
  <p>This is an example of the statement that is produced from the above code:</p>
  
  <pre><code>&gt;SELECT 'INITIAL_EXTENT', 'ALL_ALL_TABLES', 'NUMBER', 
  SUM(CASE WHEN temp.INITIAL_EXTENT IS NULL THEN 0 ELSE 1 END)  "Filled Values", 
  COUNT(temp.INITIAL_EXTENT) "Total Records" 
  FROM all_tab_columns atc 
  JOIN ALL_ALL_TABLES temp ON atc.column_name = 'INITIAL_EXTENT' AND atc.table_name =     'ALL_ALL_TABLES'
  </code></pre>