Search All Fields In All Tables For A Specific Value (Oracle)

前端 未结 16 2049
一整个雨季
一整个雨季 2020-11-22 01:05

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

There are hundreds of tables with thousands of rows in some tables so I know th

相关标签:
16条回答
  • 2020-11-22 01:55

    Here is another modified version that will compare a lower substring match. This works in Oracle 11g.

    DECLARE
      match_count INTEGER;
    -- Type the owner of the tables you are looking at
      v_owner VARCHAR2(255) :='OWNER_NAME';
    
    -- Type the data type you are look at (in CAPITAL)
    -- VARCHAR2, NUMBER, etc.
      v_data_type VARCHAR2(255) :='VARCHAR2';
    
    -- Type the string you are looking at
      v_search_string VARCHAR2(4000) :='%lower-search-sub-string%';
    
    BEGIN
      FOR t IN (SELECT table_name, column_name FROM all_tab_cols where owner=v_owner and data_type = v_data_type) LOOP
    
        EXECUTE IMMEDIATE 
        'SELECT COUNT(*) FROM '||t.table_name||' WHERE lower('||t.column_name||') like :1'
        INTO match_count
        USING v_search_string;
    
        IF match_count > 0 THEN
          dbms_output.put_line( t.table_name ||' '||t.column_name||' '||match_count );
        END IF;
    
      END LOOP;
    END;
    /
    
    0 讨论(0)
  • 2020-11-22 01:58

    Yes you can and your DBA will hate you and will find you to nail your shoes to the floor because that will cause lots of I/O and bring the database performance really down as the cache purges.

    select column_name from all_tab_columns c, user_all_tables u where c.table_name = u.table_name;
    

    for a start.

    I would start with the running queries, using the v$session and the v$sqlarea. This changes based on oracle version. This will narrow down the space and not hit everything.

    0 讨论(0)
  • 2020-11-22 01:58

    I don't of a simple solution on the SQL promprt. Howeve there are quite a few tools like toad and PL/SQL Developer that have a GUI where a user can input the string to be searched and it will return the table/procedure/object where this is found.

    0 讨论(0)
  • 2020-11-22 01:59
    SELECT * from all_objects WHERE object_name like '%your_string%';
    
    0 讨论(0)
提交回复
热议问题