CREATE PROCEDURE deleteTempTable ( TableName VARCHAR(64), PageSize int, -- 每页多少条记录 TotalPage int) -- 总页数 BEGIN DECLARE pageIndex INT(11); DECLARE tableNum VARCHAR(4); -- 执行起始位置 SET pageIndex=0; WHILE pageIndex <= TotalPage DO SET @sqlstr = CONCAT( -- sql语句 ‘delete from ‘, TableName , ‘ WHERE id >= ‘, pageIndex*PageSize, ‘ limit ‘, PageSize ); -- 日志打印 到temp_log ,temp_log 新的的只有一个字段存储操作日志 insert into temp_log select concat(‘myvar is ‘,@sqlstr); PREPARE stmt FROM @sqlstr; EXECUTE stmt; SET pageIndex = pageIndex + 1; END WHILE; END;