Zmirror 2017-05-27 09:11 采纳率: 0%
浏览 630

查询整个数据库中某个特定值所在的表和字段的方法

BEGIN
DECLARE done INT DEFAULT true;

DECLARE m_table VARCHAR(64);

DECLARE m_column VARCHAR(64);

DECLARE m_tables CURSOR

FOR

-- 查询数据库字段类型为'varchar' 的字段

select table_name,column_name

from information_schema.columns

where data_type='varchar' and table_schema='ael_web';

set @_v=v1;

open m_tables;

REPEAT

FETCH m_tables INTO m_table, m_column;

if not done then

​    ​--  拼装sql

set @m_sql = concat("insert into tmp_table select '",m_table,"' as tablename,'",m_column,"' as columnname,", m_column ," as columnvalue from ", m_table ," where " ,m_column ," like '%",v1,"%';");

-- 编译sql

prepare stmt from @m_sql;

-- 执行sql

EXECUTE stmt;  

deallocate prepare stmt;

end if;

UNTIL done END REPEAT;

CLOSE m_tables;

End $$
这是网上找的存储过程 以前没写过 一直报错

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器