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!

Locate a field 2

Status
Not open for further replies.

sxschech

Technical User
Jul 11, 2002
1,033
US
Describe Table X will give me the list of the fields, can I "query" on this so that I only see those fields that contain '%Course%' for example.

Also, If I know the name of a field, is there a query that can list out all the tables that contain that field. Example CourseNo is in Table X, Y, Z, and G.
 
Sure, sxschech, Following is my script, "show_tabs_with_col_name.sql" that shows tables and their owner(s) that contain whatever column string for which you are looking. (You cannot just copy and paste this code since it contains an "ACCEPT...PROMPT" code fragment -- you must save the code to a script file, then invoke the script as I have done here:
Code:
@show_tabs_with_col_name
Enter all, or a portion, of the column name for which you are searching: last_name

TABLE_NAME                     COLUMN_NAME
------------------------------ ---------------
DHUNT.CUSTOMER                 LAST_NAME
DHUNT.CUSTOMER2                LAST_NAME
TESTNEW.S_EMP                  LAST_NAME
TEST.ABOVE_AVG                 LAST_NAME
TEST.EMP_REC                   LAST_NAME
Here is the source code for the "show_tabs_with_col_name.sql" script:
Code:
accept col_in prompt "Enter all, or a portion, of the column name for which you are searching: "
select owner||'.'||table_name table_name
      ,column_name
  from all_tab_columns
 where column_name like upper('%&col_in%')
/
Let us know if you have questions.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Dave,
When I answer a user, I normally just give them the guery they are looking for. When you do, you give them complete utilities. Have a star for your "above and beyond" support of the users.

Bill
Oracle DBA/Developer
New York State, USA
 
Very gracious, Bill. Thanks.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Here is my star for you too. You've been most helpful. Was busy, so couldn't respond sooner to try your script.
 
Dave,
as always, an excellent and helpful thread. Can I stick my big nose in however and add a possible addendum to your code?
Might I suggest incorporating bind variables...
Code:
accept col_in prompt "Enter all, or a portion, of the column name for which you are searching: "
var x varchar2(30)

exec :x :=  '&col_in'

select owner||'.'||table_name table_name
      ,column_name
  from all_tab_columns
 where column_name like '%'||upper(:x)||'%';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top