当人们以表格形式采取行动时,我触发更新数据

i made trigger to update data when people make action in form

触发代码很好,但是在执行操作时出现此错误

error ORA-04091: table OR_HR.SELL is mutating, trigger/function may not see it.

触发码

create or replace TRIGGER  "QUALITY_EDIT" 
AFTER INSERT OR UPDATE ON Sell
FOR EACH ROW
BEGIN 
UPDATE  DRUG
SET QUANTITY =
(SELECT (DRUG.QUANTITY - SELL.QUANTITY )  FROM Sell
JOIN Drug
ON SELL.DRUG_ID = DRUG.DRUG_ID) ;
END;

我该如何解决这个问题?

你不能从刚刚被更新(或插入)的 table select,它正在 变异 并且触发器看不到它。

幸运的是,您不必从 sell select,而是使用类似这样的东西(:new 伪记录):

create or replace trigger quality_edit
  after insert or update on sell
  for each row
begin
  update drug d set
    d.quantity = d.quantity - :new.quantity
    where d.drug_id = :new.drug_id;
end;
/