我有一个SQL查询
CREATE DEFINER=`root`@`localhost` TRIGGER `trigger_vacation_mode` AFTER UPDATE ON `oc_ms_seller`
FOR EACH ROW
BEGIN
if NEW.vacation_mode <> OLD.vacation_mode THEN
UPDATE `oc_product` AS p
SET p.date_modified = NOW()
WHERE p.product_id IN (SELECT DISTINCT product_id FROM `oc_ms_seller` AS ms join
`oc_ms_product` AS mp ON ms.seller_id = mp.seller_id)
END IF;
END;
执行时我收到此错误
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
END' at line 11
答案 0 :(得分:0)
在内部查询;
的末尾添加UPDATE...
。
您需要在IF语句中终止内部查询。
CREATE DEFINER=`root`@`localhost` TRIGGER `trigger_vacation_mode` AFTER UPDATE ON `oc_ms_seller`
FOR EACH ROW
BEGIN
if NEW.vacation_mode <> OLD.vacation_mode THEN
UPDATE `oc_product` AS p
SET p.date_modified = NOW()
WHERE p.product_id IN (SELECT DISTINCT product_id FROM `oc_ms_seller` AS ms join
`oc_ms_product` AS mp ON ms.seller_id = mp.seller_id);
END IF;
END;
答案 1 :(得分:0)
您需要覆盖默认分隔符(;)
b.lua
local a = require("a.lua")
print(a.options.title)
语句将标准分隔符(分号(DELIMITER //
CREATE DEFINER=`root`@`localhost` TRIGGER `trigger_vacation_mode` AFTER UPDATE ON `oc_ms_seller`
FOR EACH ROW
BEGIN
if NEW.vacation_mode <> OLD.vacation_mode THEN
UPDATE `oc_product` AS p
SET p.date_modified = NOW()
WHERE p.product_id IN (SELECT DISTINCT product_id FROM `oc_ms_seller` AS ms join
`oc_ms_product` AS mp ON ms.seller_id = mp.seller_id);
END IF;
END//
DELIMITER ;
)更改为另一个(此处DELIMITER
)。