CREATE OR REPLACE TRIGGER TR_XT_YPMBMX_BINS_UPD_DEL BEFORE INSERT OR DELETE OR UPDATE ON XT_YPMBMX REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW declare V_count number ; --计数器 v_zsl000 number ; --总数量 V_errmsg varchar2(255); --返回提示 E_YPZSLBNWXS Exception ; --异常处理 -- MODIFICATION HISTORY -- Person Date Comments -- zhangwz 2011.07.07 每次取整药品模版维护时不能出现小数的总数量. by ZYYS-20110704-003. -- liuj 2013.11.13 注释触发器里的clbz00的处理,前台有处理 for BQ-20131030-001 -- 阮炳辉 2013.12.05 草药znxh00为空时才更新znxh00 for DZBL-20131204-001 -- dsm 2016.04.11 修改条件if :new.znxh00 is null for MZYS-20160329-002 -- xuxm 2017.04.12 修改条件nvl(:new.znxh00,-1)=-1 for ZYDZBL-20170221-001 begin if inserting then if :new.mxid00 is null then select sq_xt_ypmbmx_mxid00.nextval into :new.mxid00 from dual where rownum=1; end if; if :new.yplb00='0' then Update xt_yzmb00 set mbnrbz='1'||substr(mbnrbz,2,1)||substr(mbnrbz,3,1) where mbid00=:new.mbid00; else Update xt_yzmb00 set mbnrbz=substr(mbnrbz,1,1)||substr(mbnrbz,2,1)||'1' where mbid00=:new.mbid00; end if; if :new.yplb00='1' then--草药处方的组内序号 if nvl(:new.znxh00,0)=0 then --:new.znxh00 is null-->nvl(:new.znxh00,0)=0因为字段的默认值是0,所以这个条件永远都不满足 MZYS-20160329-002 select count(*)+1 into :new.znxh00 from xt_ypmbmx where mbid00=:new.mbid00 and yplb00='1'; end if; end if; end if; if inserting or updating then /* if :new.yplb00='0' then if (:new.pcid00 is null) or (:new.yysj00 is not null) then :new.clbz00:='1'; else :new.clbz00:='0'; end if; else if :new.ts0000>0 then :new.clbz00:='1'; else :new.clbz00:='0'; end if; end if; */ select count(*) into v_count from VW_ZS_YD0000_ALL where YPNM00=:new.ypnm00 and QZFS00='0'; if (v_count>0) and (nvl(:new.ypzsl0,0)<>0) and (:new.yplb00='0') then begin select (:new.ypzsl0/decode(:new.zldw00,zyfydw,z2j000,mzfydw,m2j000,k2j000)),YPMC00 into v_zsl000,V_errmsg from VW_ZS_YD0000_ALL where YPNM00=:new.ypnm00; if sign(v_zsl000-round(v_zsl000))<>0 then begin V_errmsg:='药品: '||V_errmsg||' 为每次取整药品,总量数据必须为整数!'; raise E_YPZSLBNWXS; end; end if; end; end if; end if; exception when E_YPZSLBNWXS then raise_application_error(-20106, V_errmsg); when others then raise_application_error(-20108, '修改记录时发生意外错误!*返回信息:'||SQLERRM); end tr_xt_ypmbmx_bins_upd_del; /