0

I would like to run a query that uses a column value (in which a tablename is stored) to determine the tablename in a from clause of a subselect.

Something like that:

SELECT column_with_tablename,

(SELECT COUNT(*) FROM VALUEOF(column_with_tablename)) as numberofitems

FROM table1

I know that this is very fragile but i need it work. (I inherited a database that stores tablenames in a column)

Is there a way ?

Lucian Depold
  • 1,999
  • 2
  • 14
  • 25

1 Answers1

2

for a pure sql solution, refer to this answer

select column_with_tablename,
       to_number(extractvalue(xmltype
         (dbms_xmlgen.getxml('select count(*) c from '||column_with_tablename)
         ),'/ROWSET/ROW/C')) as count
from table1
Community
  • 1
  • 1
HAL 9000
  • 3,877
  • 1
  • 23
  • 29