How to find the table name based on a value I pass in Oracle ? The query should check all the tables in the schema to check if the given value exists in any of the tables
1 Answer
Based on your description you basically have three different options with which you can achieve the desired result:
You can query the user_tables table and check all the tables, available on your schema. This table can be called from any user, so you won't require any specific privileges.
SELECT * FROM USER_TABLES WHERE TABLE_NAME LIKE '%SOMETHING%';
You can query the all_tables table. For this, most likely, you will need some better privileges as you would require when calling user_tables.
SELECT * FROM ALL_TABLES WHERE TABLE_NAME LIKE '%SOMETHING%';
You can query the dba_tables table. As you would expect, for this table you will need great privileges to be able to retrieve the desired information.
SELECT * FROM DBA_TABLES WHERE TABLE_NAME LIKE '%SOMETHING%';
HINT: If you are not quite sure that you are looking for a table, you can use the ALL_OBJECTS table and identify the type of the object.
'Mandelbrot'in some row in one of the columns". I've seen this kind of request several times in the past, from various users. I still don't understand what a legitimate need might be for such a search. Not to mention searching for other data types: searching for a given date, for example - not even knowing if it may be stored asdate,timestampor evenvarchar2.