遍历所有表所有列中的查找特定的内容

   某次在跟单位的同事去陕西出差,说是要在某更改某个表里的一个值,但是就是记不住是哪张表了,也记不住字段名称了,看着他在一张表一张里查询着,虽然大概知道是哪几张表,眼睛都快瞪出来,还痛苦的样子,因为数据库本身不大,又是晚上没什么人用,觉得还是写个 loop 让数据库自己找吧,还可以减少差错。

  这段代码本身不难,没什么技术含量,但是还是记下来,省得日后用到再写一遍,我也是个懒人。

 


declare

m_str varchar2(300);

m_int int;

begin

for x in (select * from col where tname in (select tname from tab where tabtype = 'TABLE' and tname not like 'BIN%') and coltype in ('VARCHAR2', 'CHAR')) loop

m_str := 'select count(*) from ' || x.tname || ' where ' || x.cname ||' like ''要查找的内容%'' ';

execute immediate m_str into m_int;

-- dbms_output.put_line(m_str);

if m_int > 0 then

dbms_output.put_line(x.tname || '.' || x.cname);

end if;

end loop;

end;

 

 


分享到:更多


引用通告: 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数:
发表评论
昵 称:
邮 箱:
主 页:
内 容: