2

I need a query (ORACLE) to pull all the table names and column names in a database for a given value?

Example: If I give a value as "TEST", I need a query which pulls all the TABLE_NAMES and COLUMN_NAMES which has the value "TEST".

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
user417572
  • 21
  • 1
  • 2
  • possible duplicate of [Search All Fields In All Tables For A Specific Value (Oracle)](http://stackoverflow.com/questions/208493/search-all-fields-in-all-tables-for-a-specific-value-oracle) – Dave Costa Aug 11 '10 at 18:05
  • possible duplicate of [SQL: Search a list of columns with a given value (within a row)](http://stackoverflow.com/questions/2140377/sql-search-a-list-of-columns-with-a-given-value-within-a-row) – APC Aug 11 '10 at 18:21

5 Answers5

1
select table_name, null column_name from all_tables where table_name like '%TEST%'
union all
select null, column_name from all_tab_columns where column_name like '%TEST%';
Codo
  • 75,595
  • 17
  • 168
  • 206
1

Another way is using bind variables within a procedure such

DEFINE vSearch = '%TEST%'

ACCEPT vSearch char PROMPT 'Enter a search value: '

SELECT * FROM USER_TAB_COLS WHERE column_name LIKE '&&vSearch' OR table_name LIKE '&&vSearch';

Montse Garcia
  • 327
  • 1
  • 3
  • 7
1

View All columns of a particular table user use "ALL_TAB_COLUMNS"

If you wants to describe a particular table user use "DESC Table_name;"

Kindly Try this..

Arun Rama Balan.G
  • 188
  • 1
  • 6
  • 24
0

You can use the USER_TAB_COLUMNS tables

del.ave
  • 1,888
  • 5
  • 17
  • 23
0

This should get you columns and tables and views:

SELECT 'Column: '||owner||'.'||table_name||'.'||column_name 
  FROM dba_tab_columns 
 WHERE column_name = 'TEST'
UNION ALL 
SELECT 'Table: '||owner||'.'||table_name 
  FROM dba_tables 
 WHERE table_name = 'TEST'
UNION ALL 
SELECT 'View: '||owner||'.'||view_name
  FROM dba_views
 WHERE view_name = 'TEST';

Note you can also use the ALL_* dictionary views if you don't have access to the DBA_ views, but you'll only see objects you have access to.

DCookie
  • 42,630
  • 11
  • 83
  • 92