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

How can we find a given string in all fields of the whole schema for Oracle?

is there an sql script to do this in Oracle? if so, how?

Can we do this with other scripts?

+4
source share
2 answers

" ALL_TAB_COLUMNS " is systable, has all the data types of table columns, etc.

" USER_TAB_COLUMNS " is systable, have all data types of table columns, etc. (which is the owner of the current user). (Thanks to Rene)

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 standard columns and table names, you can change the query as IF> 0 columns, then write the UNION query in a loop and return the cursor or return the table,

+4
source

Can we do this with other scripts?

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

0
source

Source: https://habr.com/ru/post/1346861/


All Articles