我使用sap HANA中的触发器在销售表上插入后,如何从库存中减去数量
这里是我的代码:
create trigger "KABIL_PRACTICE"."SALES_TRIGGER"
after insert on "KABIL_PRACTICE"."SALES" for each row
begin
declare Prod_ID integer;
declare Quantity integer;
select Prod_ID = "KABIL_PRACTICE"."Inventory"."P_ID",
Quantity = "KABIL_PRACTICE"."Inventory"."P_ID"
from "KABIL_PRACTICE"."Inventory"
update "KABIL_PRACTICE"."Inventory" set "Inventory" = "Inventory"-Quantity where "P_ID" = @Prod_ID
end;

答案 0 :(得分:1)
首先阅读documentation。
NEW
在哪里?
代码应该看起来更像这样:
create trigger "KABIL_PRACTICE"."SALES_TRIGGER"
after insert on "KABIL_PRACTICE"."SALES"
referencing new row new
for each row
begin
update KABIL_PRACTICE.Inventory
set Inventory = Inventory - :NEW.quantity
where P_ID = :NEW.P_ID;
end;