How does Oracle search for fields with a value in all tables under the current user?
Create or replace procedure My_pro_searchkeyword is
V_sql VARCHAR2 (4000);
V_tb_column VARCHAR2 (4000);
V_CNT number (18,0);
Cursor cur is select ' Select ' | | ' "' | | t1.table_name| | ' "." ' | | T1. column_name| | ' ' | | ', ' | | ' as COL_NAME, NVL (COUNT (t. "' | | T1. column_name| | ' "), 0) as cnt from" ' | |
t1.table_name| | ' t WHERE t. ' | | t1.column_name| | ' like '% keyword% ' as str
From cols T1 left join User_col_comments T2
on T1. Table_name=t2. TABLE_NAME and T1. Column_name=t2. column_name
Left JOIN User_tab_comments T3
on T1. Table_name=t3. table_name
WHERE not EXISTS (SELECT T4. object_name from user_objects T4
WHERE T4. Object_type= ' TABLE '
and T4. temporary= ' Y '
and T4. Object_name=t1. TABLE_NAME)
and (t1. Data_type= ' CHAR ' or T1. Data_type= ' VARCHAR2 ' or T1. Data_type= ' VARCHAR ')
ORDER by T1. TABLE_NAME, T1. column_id;
BEGIN
For i in Cur LOOP
V_sql: = I.str; --Get the SQL statement that will be executed;
EXECUTE IMMEDIATE v_sql into V_tb_column, v_cnt;
IF v_cnt > 0 Then
Dbms_output.put_line (' table: ' | | substr (V_tb_column,1,instr (V_tb_column, '. ', 1, 1)-1) | | ' column: ' | | substr (V_tb_column,instr (V_tb_column, '. ', 1, 1) +1) | |
' There ' | | To_char (v_cnt) | | ' The record contains the word string ' keyword ');
END IF;
END LOOP;
EXCEPTION when OTHERS Then
BEGIN
Dbms_output.put_line (V_sql);
Dbms_output.put_line (V_tb_column);
END;
End My_pro_searchkeyword;
Http://topic.csdn.net/u/20101110/15/06f0d4d1-f537-4124-b2f5-aabd98b2d0df.html
How does Oracle search for fields with a value in all tables under the current user? Go