创建触发器时出现mysql错误

创建触发器时出现mysql错误,mysql,sql,triggers,Mysql,Sql,Triggers,嗨,我是mysql的新手。。这是我的第一个触发器。。我正在尝试运行,但出现此错误 您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 接近'x INT;设置x=新产品价格-旧产品价格; 在第9行中插入' 分隔符$$ 创建触发器产品更新 在更新w3xab_virtuemart_产品价格之前 每行 开始 IF(新产品价格旧产品价格) 然后 声明x十进制(10,2)默认为0; 设置x=新产品价格-旧产品价格; 插入产品价格日志(虚拟零件产品id、旧产品价格、新产品价格、

嗨,我是mysql的新手。。这是我的第一个触发器。。我正在尝试运行,但出现此错误

您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 接近'x INT;设置x=新产品价格-旧产品价格; 在第9行中插入'

分隔符$$
创建触发器产品更新
在更新w3xab_virtuemart_产品价格之前
每行
开始
IF(新产品价格旧产品价格)
然后
声明x十进制(10,2)默认为0;
设置x=新产品价格-旧产品价格;
插入产品价格日志(虚拟零件产品id、旧产品价格、新产品价格、产品价格更新、价格更新日期)
值(new.virtuemart\u product\u id、old.product\u price、new.product\u price、new.x、curtime());
如果结束;
结束$$
定界符;

仅允许在BEGIN。。。结束复合语句,并且必须在其开始处,在任何其他语句之前


所以在开始后移动声明。

Jack我使用insert进入产品价格日志…工作正常…但是当我使用更新产品价格日志设置virtuemart产品id=new.virtuemart产品id,设置旧产品价格=old.product价格,设置新产品价格=new.product价格,设置产品价格更新=x,设置价格更新日期=CURDATE();它将给出这个…#1064-您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解第11行“设置旧产品价格=旧产品价格,设置新产品价格=新产品价格”附近使用的正确语法。。。。。希望你不要只使用一个
SET
,比如-
更新产品价格日志集virtuemart产品id=new.virtuemart产品id,old产品价格=old.product价格,new产品价格=new.product价格,product价格更新=x,price更新日期=CURDATE()
delimiter $$

CREATE TRIGGER product_update

BEFORE update ON w3xab_virtuemart_product_prices
FOR EACH ROW
BEGIN

IF (new.product_price <> old.product_price)
THEN 

    DECLARE x decimal(10,2) default 0;
    SET x = new.product_price - old.product_price;
    INSERT into product_price_log(virtuemart_product_id, old_product_price, new_product_price, product_price_update, price_update_date)
    VALUES (new.virtuemart_product_id, old.product_price, new.product_price, new.x, curtime());


END IF;
END$$

delimiter ;