Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return all tables with a specific value

Status
Not open for further replies.

amberlynn

Programmer
Dec 18, 2003
502
CA
Is it possible to find all tables that contain a certain field value, if I don't know the column name that contains the value?

 
Yes, AmberLynn, it is certainly possible, but imagine what it would take -- you would need either a SQL or PL/SQL script that queries...

each value
in each column
in each row
in each table
in each owner/schema...

in the entire Oracle database.

Luckily, Oracle is very well suited for doing such a thing (compared to other non-Oracle database engines). Running such a query might take hours (or days) depending upon the size of your database.

You or I could write such a script, but if I were to assist, I would need to ask several additional specification questions.

Can you offer some additional business justification for undertaking such a task?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Our company is using a custom developed app with Oracle as the backend - the company name is spelled wrong, and I've already wasted a lot of time going through table after table trying to find this error.
The database size is not huge, so I can't see it taking too much time (but what do I know :) )

 
Ah, yes. Now I understand. Your specific need simplifies things enormously since you do not need to look at values in DATE and NUMBER columns, for example.

Must you look in CLOB (Character Large OBject) columns, or can we limit the search to just VARCHAR and CHAR columns?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Also, it seems to me that the COMPANY NAME is likely to appear in only certain columns of certain tables, as well, right?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Yes, we can limit our search to only VARCHAR and CHAR columns.

I'm not sure what you mean about the name appearing in only certain columns of certain tables...

Thanks!
Amber
 
Amberlynn said:
I'm not sure what you mean about the name appearing in only certain columns of certain tables...
Amberlynn said:
...the company name is spelled wrong
My thought is that "company name" will not appear in any row of a column named "CITY", "STATE", "ZIP", or "PHONE", right? Would could simplify our search-and-update routine by identifying the only columns in which the incorrectly spelled company name could reside.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Ok, but I have no idea which column (names) it would be under. The column naming isn't your standard "City" "Phone" etc - which is part of why this is so difficult :)
Cheers,
Amber
 
Here's something to start with. Change the DBA9i to your company name, and change the owner to appropriate schema.
This produces the list of tables with columns that have chars. Then copy and paste some of those outputs to see if it finds your company name. You mentioned, you will be dealing with mispelled words, so edit accordingly.

select 'select distinct '||C.column_name||' from '||c.owner||'.'||c.table_name||' where '||c.column_name||' like ''%DBA9i%''
and rowid in ( select distinct rowid from '||c.owner||'.'||c.TABLE_NAME||' where '||c.COLUMN_NAME||' like ''%DBA9i%'');'
from dba_tables t,dba_tab_cols c where t.table_name=c.table_name and data_type like '%CHAR%' and t.owner = 'RMAN'
--not in ('OLAPSYS','OUTLN','SYS','SYSTEM')
/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top