触发器中的语法错误
我在创建 MySQL (5.1) 触发器时遇到了麻烦,我真的不明白我在这里做错了什么。这是代码:
DELIMITER //
CREATE TRIGGER CheckSoftware BEFORE INSERT ON Software
FOR EACH ROW BEGIN
-- Uppercase the first letter
SET NEW.name = CONCAT(UPPER(SUBSTRING(NEW.name, 1, 1)), SUBSTRING(NEW.name, 2));
-- If price isn't round
IF NEW.price != TRUNCATE(NEW.price) THEN
IF NEW.price - TRUNCATE(NEW.price) <= 0.49 THEN
-- Sets it to xx.49
SET NEW.price = TRUNCATE(NEW.price) + 0.49;
ELSIF (NEW.price - TRUNCATE(NEW.price)) <= 0.99 THEN
-- Sets it to xx.99
SET NEW.price = TRUNCATE(NEW.price) + 0.99;
END IF;
END IF;
END;
//
DELIMITER ;
以及 MySQL 向我抛出的内容:
ERROR 1064 (42000): 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 ') THEN
IF NEW.price - TRUNCATE(NEW.price) <= 0.49 THEN
' at line 7
非常感谢您查看它!
I'm having trouble when creating a MySQL (5.1) Trigger and I really don't see what I'm doing wrong here. Here's the code :
DELIMITER //
CREATE TRIGGER CheckSoftware BEFORE INSERT ON Software
FOR EACH ROW BEGIN
-- Uppercase the first letter
SET NEW.name = CONCAT(UPPER(SUBSTRING(NEW.name, 1, 1)), SUBSTRING(NEW.name, 2));
-- If price isn't round
IF NEW.price != TRUNCATE(NEW.price) THEN
IF NEW.price - TRUNCATE(NEW.price) <= 0.49 THEN
-- Sets it to xx.49
SET NEW.price = TRUNCATE(NEW.price) + 0.49;
ELSIF (NEW.price - TRUNCATE(NEW.price)) <= 0.99 THEN
-- Sets it to xx.99
SET NEW.price = TRUNCATE(NEW.price) + 0.99;
END IF;
END IF;
END;
//
DELIMITER ;
and what MySQL throws at my face :
ERROR 1064 (42000): 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 ') THEN
IF NEW.price - TRUNCATE(NEW.price) <= 0.49 THEN
' at line 7
Thanks a lot for looking at it !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
截断函数使用两个参数!
truncate function use two parameters!
编辑 - 差异:
EDIT - the difference: