Oracle通过一个Value值查询数据库

---恢复内容开始---

大家在想看看数据库中有哪些数据表中,哪些字段中有“helloworld” 这个字符串,现在数据库所有的表,视图都不能直接提供,所有必须通过循环去访问所有的数据表,所有的字段列,然后去访问所有的字段名。sql 如下:

declare
v_Sql varchar2(2000);
v_count number;
begin
for xx in (select t.TABLE_NAME, t.COLUMN_NAME
from user_tab_cols t ) loop
begin
v_Sql := 'select count(*) from ' ||xx.table_name ||
' where ' || xx.column_name || ' like ''%helloworld%'' ';
execute immediate v_Sql into v_count;
if (v_count >= 1) then
dbms_output.put_line('找到了结果'||xx.table_name || ':' || xx.column_name||'共'||v_count||'条');
end if;
exception
when others then
null;
end;
end loop;
dbms_output.put_line('ok');
end;

ok。

原文地址:https://www.cnblogs.com/baoyi/p/GetData.html