定义触发器时 SET 上的 MySQL 语法错误
我不明白为什么这个触发器创建语法失败:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了。显然,当作为 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!