How Does Oracle search for fields containing a certain value in all tables of the current user?

Source: Internet
Author: User

How Does Oracle search for fields containing a certain value in all tables of 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; -- Obtain the SQL statement to 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) |
'You' | to_char (v_cnt) | 'records contain the 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;

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.