具有声明语句的事件调度程序

时间:2012-11-16 07:26:27

标签: mysql

是否可以在其中创建带有declare语句的事件调度程序?

我一直试图运行此查询而没有任何成功

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

1 个答案:

答案 0 :(得分:1)

这是因为THEN之后您遗失了IF。请参见手册here

试试这个:

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 ;