CREATE OR REPLACE TRIGGER TR_YJ_YW0000_ZJRWB BEFORE INSERT OR DELETE OR UPDATE ON SD_YJ.YJ_YW0000 REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW declare V_CZLX00 char(1); V_ZJZDZ0 YJ_YW0000.YJDJH0%type; V_BMXZ00 BM_BMBM00.BMXZ00%type; V_LBBH00 BM_ZLZD00.LBBH00%type; begin select BMXZ00 into V_BMXZ00 from BM_BMBM00 where BMBH00=nvl(:new.YJKSBH,:old.YJKSBH); select LBBH00 into V_LBBH00 from bm_zlzd00 where zlxmid=nvl(:new.zlxmid,:old.zlxmid); --住院开单的和执行科室不是门诊的过滤 --if (:new.MZZYBZ = '1' or :old.MZZYBZ = '1') and V_BMXZ00<>'1' then if (:new.MZZYBZ = '1' or :old.MZZYBZ = '1') and V_LBBH00 <>'3' then return; end if; if inserting then V_CZLX00:='0'; V_ZJZDZ0:=:new.YJDJH0; elsif updating then V_CZLX00:='1'; V_ZJZDZ0:=:new.YJDJH0; elsif deleting then V_CZLX00:='2'; V_ZJZDZ0:=:old.YJDJH0; end if; if regexp_like(trim(:new.ZYHGHH), '^[0-9]+$') or regexp_like(trim(:old.ZYHGHH), '^[0-9]+$') then insert into XT_ZJRWB0 (ID0000,BM0000,ZJZDMC,ZJZDZ0,CZLX00,CZRQ00,CZSJ00,DQRQ00,DQSJ00,BLX000) values(sq_xt_zjrwb0_id0000.nextval,'YJ_YW0000','YJDJH0',V_ZJZDZ0,V_CZLX00,to_char(sysdate,'yyyymmdd'),to_char(sysdate,'hh24:mi:ss'),null,null,'1'); end if; exception when others then RAISE_APPLICATION_ERROR(-20266,substrb(nvl(SQLERRM, '原因不明出错')||'!*',1,120)); end; /