I want Search specific value in all columns of all tables in oracle 11g

…衆ロ難τιáo~ 提交于 2019-12-06 02:07:55

问题


Is it possible to search every field of every table for a particular value in Oracle.

I want to do it without using any procedure..

Can we do it with query?


回答1:


You can do it with a single query though it's a bit convoluted. This query will search all CHAR and VARCHAR2 columns in the current schema for the string '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

Note that this is an adapted version of the Laurent Schneider's query to count the rows in every table with a single query.



来源:https://stackoverflow.com/questions/5193828/i-want-search-specific-value-in-all-columns-of-all-tables-in-oracle-11g

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!