When using oracle SQL is it possible to run a query based on a text_string from a subquery? An example might clarify what I'm trying to do
select count(sql_text), sql_text
from
(select sql_text
from query_table) sql_table
group by sql_text;
The outer query is intended to count the number of results for each query retrieved from the query_table.
Is there some way I can execute the sql statements I retrieved from my query_table in the same query?
Thanks
EDIT: I was able to query sql from a table using the dbms_xmlgen.get_xml() function. I suppose that any command which caused the sql to be parsed and executed would work. That being said, here's the generic code that I was able to accomplish things with:
select to_number (
extractvalue(
xmltype(
dbms_xmlgen.getxml('select count(*) c from '|| table_name)), '/ROWSET/ROW/C'))counter,
sql_text
from
(select '('||sql_text||')' table_name
from query_table) sql_table;
While perhaps not the most elegant way to do things, it works and is a single sql statement.