【问题标题】:Identifying tables with specific contents in Oracle SQL Developer [duplicate]在 Oracle SQL Developer 中识别具有特定内容的表 [重复]
【发布时间】:2021-11-26 22:52:20
【问题描述】:

我正在尝试在包含数百个表的数据库中查找数据。我目前正在“选择凝视”每个表格以查看其内容,这需要很长时间!有没有办法可以编写查询来过滤所有具有特定内容的表?例如,假设我想在任何列中查找包含“Montana”的所有表。这可能吗?

【问题讨论】:

  • 商业建议/答案 - 询问您的同事是否有“数据模型” - 您可以浏览它以查找可能找到数据的位置
  • @thatjeffsmith 这个数据库是针对我正在使用的软件的,所以谁知道数据模型是如何设置的
  • 上述软件的名称?

标签: sql oracle oracle-sqldeveloper


【解决方案1】:

如果您遍历所有类似“字符”的列,您会这样做(它还会计算在该表/列中找到搜索字符串的次数)。我没有弗吉尼亚,所以我正在寻找 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>

【讨论】:

  • set serveroutput on declare l_cnt number; begin for cur_r in (select table_name, column_name from user_tab_columns where data_type like '%CHAR%' ) loop execute immediate 'select count(*) from ' || cur_r.table_name ||' where ' || cur_r.column_name ||' = ' || chr(39) || 'KING' || chr(39) into l_cnt; if l_cnt > 0 then dbms_output.put_line(cur_r.table_name ||'.'|| cur_r.column_name ||': '|| l_cnt); end if; end loop; end;
  • 当我尝试保存过程时收到错误“丢失或无效操作”
  • 保存程序?如何?在哪里?如您所见,我发布的代码 works;我不知道你在做什么。
  • 什么是 dbms_output ?那行是我的错误发生的地方
  • 是 dbms_output(下划线,不是点)。它是Oracle的内置包;它的过程 put_line 用于在屏幕上显示输出(就像在我的示例中一样)。您使用哪个数据库?
猜你喜欢
  • 1970-01-01
  • 2022-12-01
  • 1970-01-01
  • 2017-09-18
  • 2011-01-30
  • 2021-12-25
  • 1970-01-01
  • 2015-03-06
  • 2021-01-03
相关资源
最近更新 更多