Query/Consulta que procura um texto em todas as tabelas e colunas do tipo CHAR e ou VARCHAR2

select table_name
       ,column_name
       ,query_ds
       ,cnt
  from( select table_name,
               column_name,
               to_number(
                 extractvalue(
                   xmltype(
                     dbms_xmlgen.getxml(
                       'select count(1) c from ' || table_name ||
                       ' where UPPER(to_char(' || column_name || ')) = UPPER(''O QUE DESEJA BUSCAR'')'
                     )
                   ),
                   'ROWSET/ROW/C'
                 )
               ) cnt
               ,'select * from ' || table_name ||
               ' where UPPER(to_char(' || column_name || ')) = UPPER(''O QUE DESEJA BUSCAR'')' query_ds               
          from (select utc.*,rownum
                  from user_tab_columns utc
                 where utc.data_type in ('CHAR', 'VARCHAR2')
                   --and utc.COLUMN_NAME not like 'ATTRIBUTE%' --RESTRINGIR COLUNAS
                   --and utc.TABLE_NAME  like 'APPS_%' --APENAS TABELAS INICIADAS COM APPS
                   --and utc.TABLE_NAME  not like 'TEMP%' --RESTRINGIR TABELAS
                ) 
                )
 where cnt >= 1

 

Deixe um comentário