

出库入库这样的功能在许多系统中都有。可能叫法不一。有的可能是数量,有的可能是金额。我这里以金额为例实现出库入库也有许多方法,一种是用语言实现,一种是用触发器实现。它们各有千秋。
用语言实现
income{
id number;
pay_amount number;(入库金额字段)
}
outlay{
id number;
outlay_amount number;(出库金额字段)
}
balance
{
id number;
balance number;(余额字段)
}
下面分别在入库和出库表中建立触发器
入库表(income):
代码如下:
CREATE TRIGGER "AA"."TRI_ADD" AFTER
INSERT
OR DELETE ON "INCOME" FOR EACH ROW begin
if deleting then
update balance set balance = nvl(balance,0) - :old.pay_amount;
elsif updating then
update balance set balance = nvl(balance,0) - :old.pay_amount + :new.pay_amount;
else
update balance set balance = nvl(balance,0) + :new.pay_amount;
end if;
end;
出库表(outlay):
代码如下:
CREATE TRIGGER "AA"."TRI_CUT" AFTER
INSERT
OR DELETE
OR UPDATE ON "OUTLAY" FOR EACH ROW begin
if deleting then
update balance set balance = nvl(balance,0) + :old.outlay_amount;
elsif updating then
update balance set balance = nvl(balance,0) + :old.outlay_amount - :new.outlay_amount;
else
update balance set balance = nvl(balance,0) - :new.outlay_amount;
end if;
end;
下面我解释一下
oracle触发器,触发事件分为插入,删除,更新列三种事件,分别对应inserting /deleting/updating关键字
可以用if语句分别实现
代码如下:
if inserting then
-----
elsif updating then
-----
elsif deleting then
------
end if;
NVL(eExpression1, eExpression2)
如果 eExpression1 的计算
