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

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

    I was having following issues for @Lalit Kumars answer,

    ORA-19202: Error occurred in XML processing
    ORA-00904: "SUCCESS": invalid identifier
    ORA-06512: at "SYS.DBMS_XMLGEN", line 288
    ORA-06512: at line 1
    19202. 00000 -  "Error occurred in XML processing%s"
    *Cause:    An error occurred when processing the XML function
    *Action:   Check the given error message and fix the appropriate problem
    

    Solution is:

    WITH  char_cols AS
      (SELECT /*+materialize */ table_name, column_name
       FROM   cols
       WHERE  data_type IN ('CHAR', 'VARCHAR2'))
    SELECT DISTINCT SUBSTR (:val, 1, 11) "Searchword",
           SUBSTR (table_name, 1, 14) "Table",
           SUBSTR (column_name, 1, 14) "Column"
    FROM   char_cols,
           TABLE (xmlsequence (dbms_xmlgen.getxmltype ('select "'
           || column_name
           || '" from "'
           || table_name
           || '" where upper("'
           || column_name
           || '") like upper(''%'
           || :val
           || '%'')' ).extract ('ROWSET/ROW/*') ) ) t
    ORDER  BY "Table"
    / 
    

提交回复
热议问题