use dbmgame; delimiter // CREATE procedure clean_battle_replay(in p_version bigint, in p_day int) BEGIN DECLARE `@i` int(11); DECLARE `@sqlstr` varchar(2560); SET `@i`= 1; WHILE `@i` <= 100 DO SET @sqlstr = CONCAT("delete from tbbattle_replay_",`@i`," where `battleVersion` < ", p_version, " or `createDay` < ", p_day, ";"); prepare stmt from @sqlstr; execute stmt; SET `@i` = `@i` + 1; END WHILE; END; call clean_battle_replay( 22062900, 0); drop procedure clean_battle_replay; // delimiter ;