Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL: How do I find the table name given the column names?

Tags:

sql

oracle

If I know the names of every column of a table but not the name of the table, how do I find the name of the table I need?

like image 951
user3745942 Avatar asked Jun 18 '14 13:06

user3745942


2 Answers

Based on @Roobie's solution, the code below searches in all schemas you have access to, in case the table is not in your own schema. Also added case-insensitive matching.

SELECT owner, table_name
  FROM all_tab_columns
  WHERE UPPER(column_name) = UPPER('MYCOL');
like image 109
Joshua Huber Avatar answered Sep 19 '22 17:09

Joshua Huber


Try this (one known column):

CREATE TABLE mytab(mycol VARCHAR2(30 CHAR));

SELECT table_name FROM user_tab_columns WHERE column_name='MYCOL';

Note MYCOL is in upper case in column_name='MYCOL';

Cheers!

like image 34
Roobie Avatar answered Sep 19 '22 17:09

Roobie