假如有 tab1, tab2, tab3, tab4 几张表 ,现在模糊查询几张表中  有内容 ‘纳税人’ 的信息,
然后列出表中所有相关信息。请高人给予提示或相关代码。
表 按内容查询

解决方案 »

  1.   

    这个是以前一个差不多 的例子,利用穷举法:--在scott用户下面,搜索含有'TEST'的数据的表和字段
    declare
      v_Sql   varchar2(2000);
      v_count number;
    begin
      for xx in (select t.OWNER, t.TABLE_NAME, t.COLUMN_NAME
                   from dba_tab_columns t
                  where t.OWNER = 'SCOTT') loop
        begin
          v_Sql := 'select count(1) from ' || xx.owner || '.' || xx.table_name ||
                   ' where ' || xx.column_name || ' like ''%TEST%'' ';
          execute immediate v_Sql
            into v_count;
          if (v_count >= 1) then
            dbms_output.put_line(xx.table_name || ':' || xx.column_name);
          end if;
        exception
          when others then
            null;
        end;
      end loop;
    end;