Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 438
Royson Avatar asked Mar 04 '11 12:03

Royson


1 Answers

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.

like image 82
Justin Cave Avatar answered Oct 27 '22 00:10

Justin Cave