gpt4 book ai didi

php - 触发器 If 语句语法错误

转载 作者:行者123 更新时间:2023-11-29 00:09:38 26 4
gpt4 key购买 nike

我是 MySQL PHP WAMP 的新手,我的触发器在没有 if 语句的情况下成功创建,当我执行它时它给出错误错误是:

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 'IF (NEW.userloc_lat ='91.000000' AND NEW.userloc_lan = '181.000000') THEN ' at line 6

DELIMITER $$
CREATE TRIGGER before_new_userloc
BEFORE INSERT ON tbl_userloc
FOR EACH ROW BEGIN

INSERT INTO tbl_unknown_site
IF (NEW.userloc_lat ='91.000000' AND NEW.userloc_lan = '181.000000')
THEN SET
unknown_site_lat = NEW.userloc_lat,
unknown_site_lon = NEW.userloc_lon,
unknown_site_stt = NOW(),
unknown_site_dtm = NEW.userloc_dtm,
unknown_site_appid = NEW.userloc_appid,
unknown_site_cellid = NEW.userloc_cellid,
unknown_site_lacid = NEW.userloc_lacid,
unknown_site_subid = NEW.userloc_id;

END$$
DELIMITER ;

我认为我所看到的只会是语法错误。

userloc_latuserloc_lon的数据类型为decimal(10,6)

最佳答案

IF 应该在 INSERT 之前:

DELIMITER $$
CREATE TRIGGER before_new_userloc
BEFORE INSERT ON tbl_userloc
FOR EACH ROW BEGIN
IF (NEW.userloc_lat ='91.000000' AND NEW.userloc_lon = '181.000000')
THEN
INSERT INTO tbl_unknown_site
SET
unknown_site_lat = NEW.userloc_lat,
unknown_site_lon = NEW.userloc_lon,
unknown_site_stt = NOW(),
unknown_site_dtm = NEW.userloc_dtm,
unknown_site_appid = NEW.userloc_appid,
unknown_site_cellid = NEW.userloc_cellid,
unknown_site_lacid = NEW.userloc_lacid,
unknown_site_subid = NEW.userloc_id;
END IF;

END$$
DELIMITER ;

关于php - 触发器 If 语句语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25786411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com