尝试这个:
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();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)