MySQL遍历表

MySQL遍历表,第1张

MySQL遍历

尝试这个:

delimiter //drop procedure if exists hunt //create procedure hunt()begin    DECLARE done int default false;    DECLARE table_name CHAr(255);    DECLARE cur1 cursor for SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS         WHERe TABLE_SCHEMA = "wholesale_production" and COLUMN_NAME LIKE "%first%" ;    DECLARE ConTINUE HANDLER FOR NOT FOUND SET done = TRUE;    open cur1;    myloop: loop        fetch cur1 into table_name;        if done then leave myloop;        end if;        set @sql = CONCAt('select * from `wholesale_production`.', table_name, ' where created_at >= '2012-10-01');        prepare stmt from @sql;        execute stmt;        drop prepare stmt;    end loop;    close cur1;end //delimiter ;call hunt();


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5014746.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存