0

是否可以创建一个带有声明语句的事件调度程序?

我一直在尝试运行此查询但没有任何成功

create event dele on schedule
every 1 day 
do
begin
declare c int; 
select count(*) into c from purchased;
if(c > 5) 
delete from purchased limit 2
end if;
end
4

1 回答 1

1

这是因为您THENIF. 在此处查看手册

尝试这个:

delimiter |

CREATE EVENT dele
    ON SCHEDULE EVERY 1 DAY
    DO
    BEGIN
        DECLARE c INT;

        SELECT COUNT(*) INTO c
        FROM purchased;

        IF(c > 5)
        THEN
            DELETE FROM purchased LIMIT 2;
        END IF;
END |

delimiter ;
于 2012-11-16T07:36:55.067 回答