ORACLE——在所有表、字段中查询某个字符串并输出表名和字段名

什么都不想说,直接上干货

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 = '用户名'--查询指定所属人的所有表名和字段名
              ) loop
    begin
      v_Sql := 'select count(1) from ' || xx.owner || '.' || xx.table_name ||
               ' where ' || xx.column_name || ' like ''%192.168.1%'' ';
      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;

猜你喜欢

转载自blog.csdn.net/u010622242/article/details/83856287