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

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

    I would do something like this (generates all the selects you need). You can later on feed them to sqlplus:

    echo "select table_name from user_tables;" | sqlplus -S user/pwd | grep -v "^--" | grep -v "TABLE_NAME" | grep "^[A-Z]" | while read sw;
    do echo "desc $sw" | sqlplus -S user/pwd | grep -v "\-\-\-\-\-\-" | awk -F' ' '{print $1}' | while read nw;
    do echo "select * from $sw where $nw='val'";
    done;
    done;
    

    It yields:

    select * from TBL1 where DESCRIPTION='val'
    select * from TBL1 where ='val'
    select * from TBL2 where Name='val'
    select * from TBL2 where LNG_ID='val'
    

    And what it does is - for each table_name from user_tables get each field (from desc) and create a select * from table where field equals 'val'.

提交回复
热议问题