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

Source: Internet
Author: 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;

 

Http://topic.csdn.net/u/20101110/15/06f0d4d1-f537-4124-b2f5-aabd98b2d0df.html

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.