为什么我在使用此mysql脚本时会出错,有关触发器和过程?

时间:2019-09-16 14:22:52

标签: mysql sql triggers procedure

我练习过程和触发器,但是我的代码出错:

  

mysql>源d:/Github/Mysql/bt-trigger-3.sql;数据库更改查询   好,影响0行,1警告(0.00秒)

     

错误1064(42000):您的SQL语法有错误;检查   与您的MySQL服务器版本相对应的手册   在'where productCode = product_code;

附近使用的语法
end if;
     

在第24行结束

这是我的代码:

use classicmodels;

delimiter $$
drop trigger if exists after_update_status_orders;
create trigger after_update_status_orders after update on orders
    for each row
begin 

    declare quantity_ordered int(11) default 0;
    declare current_quantity int(11) default 0;
    declare product_code varchar(15);

    set product_code = '';

    select product_code, quantity_ordered, current_quantity;

    if old.status != 'Cancelled' and new.status = 'Cancelled' THEN
        select quantityOrdered, productCode into quantity_ordered, product_code
                from orderdetails
                where new.orderNumber = orderdetails.orderNumber;

        select quantityInStock into current_quantity from products 
                where products.productCode = productCode;


        update products 
            set quantityInStock = current_quantity + quantity_ordered;
        where productCode = product_code;

    end if;

end $$
delimiter ;mysql

0 个答案:

没有答案