欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle触发器

程序员文章站 2022-05-23 09:50:05
Oracle触发器,用于选单后修改选单的表的触发动作。 --备货检验选单后 回写备货状态 CREATE OR REPLACE TRIGGER tri_TobaccoStockI...

Oracle触发器,用于选单后修改选单的表的触发动作。

--备货检验选单后 回写备货状态

CREATE OR REPLACE TRIGGER tri_TobaccoStockINSERT
after INSERT
ON "TobaccoStockQuality"
FOR each ROW
BEGIN
UPDATE "GoodsStock" SET "FirstCheckState"=-1 WHERE "ID"=:NEW."GoodsStock_ID";
END;


--备货检验修改选单后 回写备货状态
CREATE OR REPLACE TRIGGER tri_TobaccoStockUPDATE
before UPDATE
ON "TobaccoStockQuality"
FOR each ROW
BEGIN
UPDATE "GoodsStock" SET "FirstCheckState"=decode(to_number(:NEW."AuditStatus"),0,-1) WHERE "ID"=:NEW."GoodsStock_ID";
IF :NEW."GoodsStock_ID"<>:OLD."GoodsStock_ID" THEN
UPDATE "GoodsStock" SET "FirstCheckState"=-1 WHERE "ID"=:OLD."GoodsStock_ID";
END IF;
END;


--备货检验删除单据后 回写备货状态
CREATE OR REPLACE TRIGGER tri_TobaccoStockDELETE
before DELETE
ON "TobaccoStockQuality"
FOR each ROW
BEGIN
UPDATE "GoodsStock" SET "FirstCheckState"=-1 WHERE "ID"=:OLD."GoodsStock_ID";
END;