请教诸位高手,
假设我只知道Oracle数据库中某表某记录某字段的值包含一个特定字符,比如“ABC”。
那么我怎么把以包含“ABC”为值的所有字段、相关记录、和相关表都找出来?
请写出具体方法,谢谢!

解决方案 »

  1.   

    只有写个过程,通过dba_tab_columns得到各个表的各个列,然后再在各个列中去查询特定的值。
      

  2.   

    调试了很长时间,菜就一个字
    注意个问题,需要先确定字段类型,比如字符还是数字。
    declare
      sReturn int;
        v_stmt  varchar2(500);
        type cursor_type is ref cursor;
        c1 cursor_type;
        c2 cursor_type;
        v_table_name varchar2(500);
        v_column_name varchar2(500);
        data_type varchar2(20);
    begin
        --data_type;
        data_type:='VARCHAR2';
        open c1 for 'select table_name,column_name from USER_TAB_COLUMNS '||' where data_type='''||data_type||'''';
        dbms_output.put_line('select table_name,column_name from USER_TAB_COLUMNS '||' where data_type='''||data_type||'''');
        
        loop
        
        fetch c1 into v_table_name,v_column_name;
        exit when c1%notfound;
           --dbms_output.put_line(v_table_name||'---'||v_column_name);
        
        
        
        v_stmt:='select count(*) from '||v_table_name||' where '||v_column_name||'=''SMITH''';
        --dbms_output.put_line(v_stmt);
        open c2 for v_stmt;
        loop 
        fetch c2 into sReturn;
        exit when c2%notfound;
             if sReturn=1 then
            dbms_output.put_line(v_table_name||'---'||v_column_name);
            end if;
        end loop;
        
        end loop;
    exception
        when others then
            dbms_output.put_line(sqlerrm);
            raise;
           
    end;