问题
I'm trying to search using a String for all tables but it didn't seem to work in BLOB columns. I got this procedure from a forum. It's working in searching string but not in BLOB. Can you please help me please?
create or replace procedure find_string( p_str in varchar2 )
authid current_user
as
l_query long;
l_case long;
l_runquery boolean;
l_tname varchar2(30);
l_cname varchar2(30);
l_x number;
begin
dbms_application_info.set_client_info( '%' || upper(p_str) || '%' );
for x in (select * from user_tables )
loop
l_query := 'select ''' || x.table_name || ''', $$
from ' || x.table_name || '
where rownum = 1 and ( 1=0 ';
l_case := 'case ';
l_runquery := FALSE;
for y in ( select *
from user_tab_columns
where table_name = x.table_name
)
loop
l_runquery := TRUE;
l_query := l_query || ' or upper(' || y.column_name ||
') like userenv(''client_info'') ';
l_case := l_case || ' when upper(' || y.column_name ||
') like userenv(''client_info'') then ''' ||
y.column_name || '''';
end loop;
if ( l_runquery )
then
l_case := l_case || ' else NULL end';
l_query := replace( l_query, '$$', l_case ) || ')';
begin
execute immediate l_query into l_tname, l_cname;
dbms_output.put_line
( 'Found in ' || l_tname || '.' || l_cname );
exception
when no_data_found then
/*select 0 into l_x from dual;*/
dbms_output.put( '.');
end;
end if;
end loop;
end;
Thank you very much!
回答1:
You cannot search for strings within a BLOB column using the normal SQL String operations. You would need to use the dbms_lob package to achieve your goal.
Refer to this link for an example of how it is to be done. There are plenty of examples on Google too which can guide you further.
来源:https://stackoverflow.com/questions/24319492/oracle-search-all-tables-of-a-string-with-blob-column