请求大佬看看我这个存储过程写的可以吗?还可以优化吗?
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`()
BEGIN
#Routine body goes here...
DECLARE i INT;
set i=0;
while i>=9 do
#查询类型
select ELE_TYPE into @eleType from TI_ENERGY_ELE2 group by ELE_TYPE order by ELE_TYPE limit i,1;
#删除这个类型一周前的数据
DELETE FROM TI_ENERGY_ELE2 WHERE ELE_TYPE = @eleType AND CREATE_DATE<= DATE_SUB(CURDATE(), INTERVAL 8 DAY);
set i =i+1;
end while;
END
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`()
BEGIN
#Routine body goes here...
DECLARE i INT;
set i=0;
while i>=9 do
#查询类型
select ELE_TYPE into @eleType from TI_ENERGY_ELE2 group by ELE_TYPE order by ELE_TYPE limit i,1;
#删除这个类型一周前的数据
DELETE FROM TI_ENERGY_ELE2 WHERE ELE_TYPE = @eleType AND CREATE_DATE<= DATE_SUB(CURDATE(), INTERVAL 8 DAY);
set i =i+1;
end while;
END