在 Oracle SQL 开发人员中识别具有特定内容的表

Identifying tables with specific contents in Oracle SQL Developer

我试图在包含数百个 table 的数据库中查找数据。我目前正在“select 盯着”每个 table 查看他们的内容,而且要花很长时间!有没有一种方法可以编写查询来过滤所有具有特定内容的 table?例如,假设我想在任何列中找到所有包含“Montana”的 table。这可能吗?

如果您遍历所有类似“字符”的列,您会这样做(它还会计算在 table/column 中找到搜索字符串的次数)。我没有任何 Virginia,所以我正在搜索 KING。

SQL> set serveroutput on
SQL> declare
  2    l_cnt number;
  3  begin
  4    for cur_r in (select table_name, column_name
  5                  from user_tab_columns
  6                  where data_type like '%CHAR%'
  7                 )
  8    loop
  9      execute immediate 'select count(*) from ' || cur_r.table_name ||
 10                        '  where ' || cur_r.column_name ||' = ' ||
 11                        chr(39) || 'KING' || chr(39)
 12                   into l_cnt;
 13      if l_cnt > 0 then
 14         dbms_output.put_line(cur_r.table_name ||'.'|| cur_r.column_name ||': '|| l_cnt);
 15      end if;
 16    end loop;
 17  end;
 18  /
EMP.ENAME: 1
V_EMP.ENAME: 1

PL/SQL procedure successfully completed.

SQL>