这些语句列出了包含某些列的所有列。 Is也在搜索视图,我需要知道如何跳过视图。
DECLARE
match_count integer;
v_search_string varchar2(4000) := 'FE/Operational';
BEGIN
FOR t IN (SELECT owner,
table_name,
column_name
FROM all_tab_columns
WHERE data_type in ('VARCHAR2','VARCHAR','NCHAR','NVARCHAR2') )
LOOP
BEGIN
EXECUTE IMMEDIATE
'SELECT COUNT(*) FROM '||t.owner || '.' || t.table_name||
' WHERE '||t.column_name||' = :1'
INTO match_count
USING v_search_string;
IF match_count > 0 THEN
dbms_output.put_line( t.owner || '.' || t.table_name ||'
'||t.column_name||' '||match_count );
END IF;
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'Error encountered trying to read ' ||
t.column_name || ' from ' ||
t.owner || '.' || t.table_name );
dbms_output.put_line(SQLERRM);
END;
END LOOP;
END;
/
答案 0 :(得分:0)
您可以在all_objects
上加入查询,并检查对象类型是否为表:
SELECT owner,
table_name,
column_name
FROM all_tab_columns atc
JOIN all_object ao ON atc.table_name = ao.object_name AND
atc.owner = ao.owner
WHERE data_type IN ('VARCHAR2', 'VARCHAR', 'NCHAR', 'NVARCHAR2') AND
object_type = 'TABLE'
答案 1 :(得分:0)
您可以使用ALL_OBJECT
视图仅包括表,如下所示:
SELECT
ATT.OWNER,
ATT.TABLE_NAME,
ATT.COLUMN_NAME
FROM
ALL_TAB_COLUMNS ATT JOIN ALL_OBJECTS AO
ON ATT.TABLE_NAME = AO.OBJECT_NAME AND ATT.OWNER = AO.OWNER
WHERE
DATA_TYPE IN (
'VARCHAR2',
'VARCHAR',
'NCHAR',
'NVARCHAR2'
)
AND AO.OBJECT_TYPE = 'TABLE'