各位老师,我写了个触发器,插入时,按照对应的源头备料单ID和物料编码还有批次号进行验证,如果在领用的批次号里面不允许做退料操作,但是编译成功不生效,请各位大神指点。
脚本如下
CREATE OR REPLACE TRIGGER TRI_IC_MATERIAL
before insert ON Ic_Material_b
for each row
declare
i_nnum NUMBER(28);
BEGIN
if :new.nnum < 0 then
begin
--根据物料+批号+备料计划表体id去汇总数量。
select nvl(sum(ic_material_b.nnum), 0)
into i_nnum
from ic_material_b
where :new.cpickmbid = ic_material_b.cpickmbid
and :new.cmaterialvid = ic_material_b.cmaterialvid
and :new.vbatchcode in (ic_material_b.vbatchcode);
if i_nnum + :new.nnum < i_nnum then
raise_application_error(-2001,'退料数量与批次号有误');
end if;
end;
end if;
end TRI_IC_MATERIAL;