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

前端 未结 2 1061
滥情空心
滥情空心 2021-01-19 05:53

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 we do i

相关标签:
2条回答
  • 2021-01-19 06:10

    Can we do it by any other script?

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

    0 讨论(0)
  • 2021-01-19 06:22

    "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,

    0 讨论(0)
提交回复
热议问题