【问题标题】:ORACLE Search All Tables of a String with BLOB ColumnORACLE 使用 BLOB 列搜索字符串的所有表
【发布时间】:2014-08-10 18:03:37
【问题描述】:

我正在尝试使用字符串搜索所有表,但它似乎不适用于 BLOB 列。我从一个论坛得到这个程序。它在搜索字符串中起作用,但在 BLOB 中不起作用。 你能帮帮我吗?

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;

非常感谢!

【问题讨论】:

    标签: oracle stored-procedures blob


    【解决方案1】:

    您不能使用普通的 SQL 字符串操作在 BLOB 列中搜索字符串。您需要使用dbms_lob 包来实现您的目标。

    请参阅this 链接,了解如何完成此操作的示例。 Google 上也有很多示例,可以进一步指导您。

    【讨论】:

      猜你喜欢
      • 2011-09-17
      • 2022-09-23
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多