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

前端 未结 16 2344
一整个雨季
一整个雨季 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:53

    Borrowing, slightly enhancing and simplifying from this Blog post the following simple SQL statement seems to do the job quite well:

    SELECT DISTINCT (:val) "Search Value", TABLE_NAME "Table", COLUMN_NAME "Column"
    FROM cols,
         TABLE (XMLSEQUENCE (DBMS_XMLGEN.GETXMLTYPE(
           'SELECT "' || COLUMN_NAME || '" FROM "' || TABLE_NAME || '" WHERE UPPER("'
           || COLUMN_NAME || '") LIKE UPPER(''%' || :val || '%'')' ).EXTRACT ('ROWSET/ROW/*')))
    ORDER BY "Table";
    

提交回复
热议问题