直截了当,我在触发器mysql中使用条件状态时遇到问题。
有2个状态,如果状态为“来宾”,则执行某项操作。否则执行另一项操作。

这是我已经做过的:

CREATE TRIGGER `update-gain` AFTER INSERT ON `payment`
FOR EACH ROW BEGIN
declare v_profit integer;
declare v_deposit integer;
declare v_status CHAR;

select (status) into v_status from item where item.id_item=new.id_item;
select sum(profit_owner) into v_profit from payment where payment.id_item=new.id_item;
select sum(profit_guest ) into v_deposit from payment where payment.id_item=new.id_item;

if v_status like 'guest' then
INSERT INTO gain
(gain.profit, gain.modal,gain.date)
VALUES
(v_profit,v_deposit,new.date)
ON DUPLICATE KEY UPDATE
gain.profit = gain.profit+new.profit_owner,
gain.modal = gain.deposit+new.profit_guest;

else
INSERT INTO gain
(gain.profit,gain.tanggal)
VALUES
(v_profit,new.tgl_stok)
ON DUPLICATE KEY UPDATE
gain.profit = gain.profit_owner+new.profit_owner;

end if;
END


到目前为止,我正在使用'like'子句,但条件始终为true,即使v_status也不是'guest'。

我在这里做错了什么?
谢谢 :)

最佳答案

更改

if v_status like 'guest' then


对于

if v_status = 'guest' then

关于mysql - 如果有条件在mysql中触发?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45402942/

10-11 10:53