I have the following table name template, there are a couple with the same name and a number at the end: fmj.backup_semaforo_geo_THENUMBER, for example:
select * from fmj.backup_semaforo_geo_06391442
select * from fmj.backup_semaforo_geo_06398164
...
Lets say I need to select a column from every table which succeeds with the ‘fmj.backup_semaforo_geo_%’ filter, I tried this:
SELECT calle --This column is from the backup_semaforo_geo_# tables
FROM (SELECT table_name
FROM all_tables
WHERE owner = 'FMJ' AND table_name LIKE 'BACKUP_SEMAFORO_GEO_%');
But I’m getting the all_tables tables name data:
TABLE_NAME
----------
BACKUP_SEMAFORO_GEO_06391442
BACKUP_SEMAFORO_GEO_06398164
...
How can I achieve that without getting the all_tables output?
Thanks.
Presumably your current query is getting
ORA-00904: "CALLE": invalid identifier, because the subquery doesn’t have a column calledCALLE. You can’t provide a table name to a query at runtime like that, unfortunately, and have to resort to dynamic SQL.Something like this will loop through all the tables and for each one will get all the values of
CALLEfrom each one, which you can then loop through. I’ve usedDBMS_OUTPUTto display them, assuming you’re doing this in SQL*Plus or something that can deal with that; but you may want to do something else with them.