我有两个表Orderitems:
"ORDER_ITEMS_CODE" VARCHAR2(20) NOT NULL ENABLE,
"ORDER_CODE" VARCHAR2(20) NOT NULL ENABLE,
"ITEM_CODE_ORDERS" VARCHAR2(20) NOT NULL ENABLE,
"ORDER_QUANTITY" NUMBER(4,0) NOT NULL ENABLE,
"ORDER_UNIT" VARCHAR2(5) NOT NULL ENABLE,
"UNIT_PRICE" NUMBER(38,5),
"ORDERED_IN" VARCHAR2(6),
"OR_QUANTITY_TON" NUMBER(38,5),
"Warehouse_CODE" VARCHAR2(20) NOT NULL ENABLE
另一个表是库存:
"INVENTORY_CODE" VARCHAR2(20) NOT NULL ENABLE,
"ITEM_CODE" VARCHAR2(20) NOT NULL ENABLE,
"WAREHOUSE_CODE" VARCHAR2(20),
"IN_Q_TON" NUMBER(38,5),
"OR_Q_TON" NUMBER(38,5)
我创建了一个触发器来计算 "OR_QUANTITY_TON" = Sum ("OR_QN_TON")
create or replace trigger sum_Or_IT
after insert or update or delete on orderitems
begin
update INVENTORY set OR_Q_TON = (
select sum(or_quantity_ton) from orderitems
where
orderitems.item_code_orders = INVENTORY.item_code
and
warehouse_code = '1');
end;
这是一个库存表,列 OR_Q_TON 是每个项目的订购数量的总和,但是如果订单中不存在某个项目,我希望订单数量为零。如果表“Orderitems”中不存在“item_code_orders”,我想例外,那么 OR_Q_TON = 0
我试过了,但没有用我得到(-)不是(0)
EXCEPTION
WHEN NO_DATA_FOUND THEN
update INVENTORY set OR_Q_TON = 0 ;