0
我做了新的触发器,它必须更新员工的工资。它从表格付款中获取2个值(现金和月),并将它们分成一列“how_much_to_pay”。无法更新触发器中的表
我看了一下题目: MySQL triggers cannot update rows in same table the trigger is assigned to. Suggested workaround?
但didin't帮我,因为他们只用1台,它们可以把“新”没有问题。
这里是我的触发器:
create trigger pay_out before insert on `payment_out`
for each row
then
UPDATE `payment_out` o
INNER JOIN payment p ON p.id_1 = o.id_1 AND o.id2 = p.id2
SET o.`how_much_to_pay` = p.cash/p.months;
end;
$$
下面是表:
table payment_out
id1
id2
how_much_to_pay
table payment
id1
id2
cash
months
和错误本身:
1442 - Can't update table payment_out in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
那么,这个工作,但“多少钱”是NULL,即使现金= 8000,月= 8。 – trinny
如果p.cash或p.months之一是空值。尝试从触发器运行SELECT,将正确的值添加到WHERE条件。结果是什么? – Devart
当我注意到它时,我将它更改为0.00。 – trinny