我想在oracle 11g中所有表的所有列中搜索特定值

Roy*_*son 6 search oracle11g

是否可以在每个表的每个字段中搜索Oracle中的特定值.

我想这样做而不使用任何程序..

我们可以用查询来做吗?

Jus*_*ave 12

你可以用一个查询来完成它,虽然它有点复杂.此查询将搜索当前架构中字符串的所有CHAR和VARCHAR2列'JONES'

select table_name,
       column_name
  from( select table_name,
               column_name,
               to_number(
                 extractvalue(
                   xmltype(
                     dbms_xmlgen.getxml(
                       'select count(*) c from ' || table_name ||
                       ' where to_char(' || column_name || ') = ''JONES'''
                     )
                   ),
                   'ROWSET/ROW/C'
                 )
               ) cnt
          from (select utc.*, rownum
                  from user_tab_columns utc
                 where data_type in ('CHAR', 'VARCHAR2') ) )
 where cnt >= 0
Run Code Online (Sandbox Code Playgroud)

请注意,这是Laurent Schneider查询的改编版本,可以使用单个查询计算每个表中的行数.