ORACLE Search All Tables of a String with BLOB Column

强颜欢笑 提交于 2020-01-16 19:17:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!