Oracle SQL:如何在给定列名的情况下找到表名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24287546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL: How do I find the table name given the column names?
提问by user3745942
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?
如果我知道表的每一列的名称但不知道表的名称,我如何找到我需要的表的名称?
回答by Joshua Huber
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.
基于@Roobie 的解决方案,下面的代码会在您有权访问的所有架构中进行搜索,以防该表不在您自己的架构中。还添加了不区分大小写的匹配。
SELECT owner, table_name
FROM all_tab_columns
WHERE UPPER(column_name) = UPPER('MYCOL');
回答by Roobie
Try this (one known column):
试试这个(一个已知的列):
CREATE TABLE mytab(mycol VARCHAR2(30 CHAR));
SELECT table_name FROM user_tab_columns WHERE column_name='MYCOL';
CREATE TABLE mytab(mycol VARCHAR2(30 CHAR));
SELECT table_name FROM user_tab_columns WHERE column_name='MYCOL';
Note MYCOL
is in uppercase in column_name='MYCOL'
;
注意MYCOL
是大写的column_name='MYCOL'
;
Cheers!
干杯!
回答by souvik
select * from all_updatable_columns where column_name like 'reqd col name';