0

我有桌子Inventory

"INVENTORY_CODE" VARCHAR2(20) NOT NULL ENABLE 
"ITEM_CODE"      VARCHAR2(20) NOT NULL ENABLE 
"WAREHOUSE_CODE" VARCHAR2(20) 
"CON_TON"        NUMBER(38,5) 
"IN_Q_TON"       NUMBER(38,5) 
"OR_Q_TON"       NUMBER(38,5) 
"RES_TON"        NUMBER(38,5) 
"RET_TON"        NUMBER(38,5)  
"ST_INV"         NUMBER(38,5)

和另一张桌子Inventory_warehouse

"CODE" VARCHAR2(20) NOT NULL ENABLE 
"ITEM_CODE" VARCHAR2(20) NOT NULL ENABLE 
"QUANTITY_AV_TON" NUMBER(38,5) 
"QUANTITY_AV_REAM" NUMBER(38,5) 
"QUANTITY_AV_SHEET" NUMBER(38,5)

我想触发计算QUANTITY_AV_TON

作为

QUANTITY_AV_TON = IN_Q_TON + RES_TON + RET_TON + ST_INV - CON_TON - OR_Q_TON

我创建了这个触发器,但它不起作用

create or replace trigger QUANTITY_TON
AFTER insert or update or delete on INVENTORY
for each row
begin
  UPDATE INVENTORY_WAREHOUSE
     SET QUANTITY_AV_TON =
         select (IN_Q_TON + RES_TON + RET_TON + ST_INV - CON_TON -OR_Q_TON)
         from inventory
         where INVENTORY.item_code = INVENTORY_WAREHOUSE.item_code;
end;

IN_Q_TON, RES_TON, RET_TON, ST_INV, CON_TON,的值是OR_Q_TON使用触发器从其他表中计算出来的

4

1 回答 1

0

如果要从正在处理的触发器中的行的上下文值执行计算。这通常通过使用 ":NEW" 变量来完成。我已经编辑了触发器,但无法运行它,所以请尝试一下。请阅读Oracle 触发器文档

CREATE OR REPLACE TRIGGER QUANTITY_TON
   AFTER INSERT OR UPDATE OR DELETE
   ON INVENTORY
   FOR EACH ROW
BEGIN
   UPDATE INVENTORY_WAREHOUSE
      SET QUANTITY_AV_TON =   :new.IN_Q_TON
                            + :new.RES_TON
                            + :new.RET_TON
                            + :new.ST_INV
                            - :new.CON_TON
                            - :new.OR_Q_TON
   WHERE INVENTORY_WAREHOUSE.ITEM_CODE = :new.ITEM_CODE;

END;
于 2013-08-20T14:37:35.317 回答