Answers:
要查找具有特定列的所有表:
select owner, table_name from all_tab_columns where column_name = 'ID';
要查找具有任何或所有4列的表:
select owner, table_name, column_name
from all_tab_columns
where column_name in ('ID', 'FNAME', 'LNAME', 'ADDRESS');
要查找具有全部4列(不丢失)的表:
select owner, table_name
from all_tab_columns
where column_name in ('ID', 'FNAME', 'LNAME', 'ADDRESS')
group by owner, table_name
having count(*) = 4;
column_name
+ like
:select owner, table_name, column_name from all_tab_columns where column_name like 'someField%';
所需的数据在“ cols”元数据表中:
SELECT * FROM COLS WHERE COLUMN_NAME = 'id'
这将为您提供一个表列表,其中包含您想要的所有列:
select distinct
C1.TABLE_NAME
from
cols c1
inner join
cols c2
on C1.TABLE_NAME = C2.TABLE_NAME
inner join
cols c3
on C2.TABLE_NAME = C3.TABLE_NAME
inner join
cols c4
on C3.TABLE_NAME = C4.TABLE_NAME
inner join
tab t
on T.TNAME = C1.TABLE_NAME
where T.TABTYPE = 'TABLE' --could be 'VIEW' if you wanted
and upper(C1.COLUMN_NAME) like upper('%id%')
and upper(C2.COLUMN_NAME) like upper('%fname%')
and upper(C3.COLUMN_NAME) like upper('%lname%')
and upper(C4.COLUMN_NAME) like upper('%address%')
要在其他架构中执行此操作,只需在表前面指定架构,如
SELECT * FROM SCHEMA1.COLS WHERE COLUMN_NAME LIKE '%ID%';
如果要将多个模式的搜索合并为一个输出结果,则可以执行以下操作:
SELECT DISTINCT
'SCHEMA1' AS SCHEMA_NAME
,TABLE_NAME
FROM SCHEMA1.COLS
WHERE COLUMN_NAME LIKE '%ID%'
UNION
SELECT DISTINCT
'SCHEMA2' AS SCHEMA_NAME
,TABLE_NAME
FROM SCHEMA2.COLS
WHERE COLUMN_NAME LIKE '%ID%'
SELECT * FROM COLS
从我的架构中不返回任何内容。我在表上只有选择特权。选择的内容不足以允许我通过COLS进行查看吗?
select * from schema1.cols
给我一个table or view does not exist
错误。这与特权的设置有关吗?
这是我们保存到findcol.sql的文件,因此我们可以在SQLPlus中轻松运行它
set verify off
clear break
accept colnam prompt 'Enter Column Name (or part of): '
set wrap off
select distinct table_name,
column_name,
data_type || ' (' ||
decode(data_type,'LONG',null,'LONG RAW',null,
'BLOB',null,'CLOB',null,'NUMBER',
decode(data_precision,null,to_char(data_length),
data_precision||','||data_scale
), data_length
) || ')' data_type
from all_tab_columns
where column_name like ('%' || upper('&colnam') || '%');
set verify on