开发者

Search for a given string in all fields of an entire schema for Oracle

开发者 https://www.devze.com 2023-02-22 22:30 出处:网络
How can we Search for a given string in all fields of an entire schema for Oracle? is there an sql script to do the above in Oracle? if yes, how?

How can we Search for a given string in all fields of an entire schema for Oracle?

is there an sql script to do the above in Oracle? if yes, how?

Can 开发者_JAVA百科we do it by any other script?


"ALL_TAB_COLUMNS" is a systable, have all table columns data type etc.

"USER_TAB_COLUMNS" is a systable, have all table columns data type etc (which owner is current user). (Thanks Rene)

An Example:

 SET SERVEROUTPUT ON SIZE 100000 -- maybe you have a lot of table and columns

    DECLARE
      matches INTEGER;
    BEGIN
      FOR columns IN (SELECT table_name, column_name FROM user_tab_columns where data_type = 'VARCHAR2') LOOP

        EXECUTE IMMEDIATE
          'SELECT COUNT(*) FROM '||t.table_name||' WHERE instr('||t.column_name||' , :1) > 0'
          INTO matches
          USING 'What you search';

        IF matches > 0 THEN
          dbms_output.put_line( t.table_name ||' '||t.column_name||' '||matches );
        END IF;

      END LOOP;

    END;
    /

this query will output table_name '' column_name'' and count, if you have standart column and table names, you can change query as IF columns > 0 then write a query UNION in loop and return the cursor, or return a table,


Can we do it by any other script?

You can dump the database to disk as text, then use grep.

0

精彩评论

暂无评论...
验证码 换一张
取 消