MySQL事件If语句END IF错误 [英] MySQL Event If Statement END IF Error

查看:1255
本文介绍了MySQL事件If语句END IF错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试创建一个重置soldout状态(指示为1)的MySQL事件.

Trying to create a MySQL event that resets a soldout status (indicated as 1).

我要创建的逻辑是一个简单的IF语句.

The logic I'm trying to create is a simple IF statement.

如果soldout = 1Quantity> 0在同一行中

If soldout = 1 AND Quantity > 0 in the same row

soldout更新为0

这是我的活动

CREATE EVENT soldoutreset
ON SCHEDULE EVERY 5 MINUTE
DO
IF db.Inventory.soldout = 1
AND db.Inventory.Quantity > 0 THEN
UPDATE db.Inventory SET soldout = 0
WHERE soldout = 1 AND Quantity > 1
END IF;

这会导致错误'END IF' at line 9

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF' at line 9

谁能告诉我为什么这不起作用?

Can anyone tell why this is not working?

推荐答案

这应该有效,您缺少语法的一部分:

This should work, you are missing a part of the syntax:

DELIMITER |

CREATE EVENT soldoutreset
ON SCHEDULE EVERY 5 MINUTE
    DO
    BEGIN
        IF db.Inventory.soldout = 1 AND db.Inventory.Quantity > 0 THEN
            UPDATE db.Inventory SET soldout = 0
            WHERE soldout = 1 AND Quantity > 1;
        END IF;
    END |

DELIMITER ;

更新:

如果事件未按预期运行,则可能是因为事件计划程序已关闭.可以通过以下方式启用它:

If the event is not running as expected, it might be because the event scheduler is off. It can be enabled with:

SET GLOBAL event_scheduler = ON; 

这篇关于MySQL事件If语句END IF错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆