定义触发器时 SET 上的 MySQL 语法错误

发布于 2024-10-03 18:40:20 字数 506 浏览 0 评论 0原文

我不明白为什么这个触发器创建语法失败:

CREATE TRIGGER mytrigger BEFORE UPDATE ON mytable
FOR EACH ROW
BEGIN
    IF NEW.col1 = 0 AND NEW.col2 != '' AND NEW.col3 > 0 THEN
        SET NEW.col1 = NEW.col3 - (10 * 60);
    END IF;
END;

MySQL 说第 5 行有一个语法错误,就在 SET 语句之前/之上。我正在使用 MySQL 5.0.27。我看不出有什么问题,因为它与给出的示例几乎相同 在手册中 3/4s 下来。

PS:我在 PhpMyAdmin 的 SQL 选项卡中输入此内容。添加“分隔符”语句没有帮助。有什么线索吗?提前致谢!

I can't figure out why this trigger creation syntax fails:

CREATE TRIGGER mytrigger BEFORE UPDATE ON mytable
FOR EACH ROW
BEGIN
    IF NEW.col1 = 0 AND NEW.col2 != '' AND NEW.col3 > 0 THEN
        SET NEW.col1 = NEW.col3 - (10 * 60);
    END IF;
END;

MySQL says there's a syntax error at line 5, just before/on the SET statement. I'm using MySQL 5.0.27. I can't see what's wrong, seeing as it's pretty much identical to the example given in the manual 3/4s down.

PS: I'm entering this in the SQL tab on PhpMyAdmin. Adding "delimiter" statements doesn't help. Any clues? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤凫 2024-10-10 18:40:20

我找到了。显然,当作为 SQL 查询的一部分输入时,PhpMyAdmin 会忽略 MySQL 的分隔符命令。相反,您需要在 SQL 查询下方的单独表单字段中设置分隔符。我完全错过了!

I found it. Apparently PhpMyAdmin ignores MySQL's delimiter command when entered as part of an SQL query. Instead, you need to set the delimiter in a separate form field below the SQL query. I totally missed that!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文