[英]how to make an update trigger query in pl sql
I have 2 tables (1) product_warehouse
and (2) Return_Vendor Invoice
.我有 2 个表 (1)
product_warehouse
和 (2) Return_Vendor Invoice
。 i have to update the quantity
in product_warehouse
by trigger according to the value of Return_Vendor Invoice
Table.我必须根据
Return_Vendor Invoice
Table 的值通过触发器更新product_warehouse
的quantity
。 where Item_code
is unique key in both tables.其中
Item_code
是两个表中的唯一键。
For example if the product_warehouse contain 3 quantities , and the shopkeeper returns 1 quantity to vendor then it should be 2 in the Product_warehouse
.例如,如果 product_warehouse 包含 3 个数量,并且店主将 1 个数量返回给供应商,那么
Product_warehouse
中的数量应该是 2。 update query will also acceptable.更新查询也可以接受。
create or replace trigger tiuda_return_vendor after insert or update or delete
on return_vendor is
begin
update product_wherehouse
set
quantity = quantity - (:new.quantity - nvl(:old.quantity, 0)
where
item_code = nvl(:new.item_code, :old.item_code);
end;
This trigger works in most cases.此触发器在大多数情况下都有效。 You can insert update or delete the return line.
您可以插入更新或删除返回行。
Only thing is: when updating, you cannot update the item_code itself, because the update statement doesn't take that into account.唯一的问题是:更新时,您不能更新 item_code 本身,因为更新语句没有考虑到这一点。 You could easily solve that, but I don't know if it's in your requirements.
您可以轻松解决该问题,但我不知道它是否符合您的要求。 I usually don't change values like that, but rather remove the item and add a new line for a different item.
我通常不会像这样更改值,而是删除该项目并为不同的项目添加一个新行。
Updating the quantity works fine.更新数量工作正常。 If you update the quantity, the difference between old and new is calculated and that difference is used to modify the stock quantity in the wherehouse.
如果您更新数量,则会计算新旧之间的差异,并使用该差异来修改 wherehouse 中的库存数量。
create or replace
TRIGGER "WR_RETURN_INVOICE_UPDATE_TRG"
AFTER UPDATE ON RETURN_INVOICE
FOR EACH ROW
BEGIN
UPDATE PRODUCT_WAREHOUSE
SET QUANTITY=QUANTITY-:OLD.QUANTITY
WHERE ITEM_CODE=:OLD.ITEM_CODE;
END WR_RETURN_INVOICE_UPDATE_TRG;
Try this one it will works.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.