How does Oracle search for fields with a value in all tables under the current user? Go

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.