CREATE OR REPLACE TRIGGER TR_YJ_YW0000_BINS_UPD BEFORE INSERT OR UPDATE ON SD_YJ.YJ_YW0000 REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW declare Errstr varchar2(200); Ecustom EXCEPTION; vcounter NUMBER(5); Vbrzt00 ZY_BRXXB0.BRZT00%type; Vzyid00 ZY_BRXXB0.ZYID00%type; begin if updating then --更改 if :new.HBZYXM='2' then UPDATE JY_YW0000 SET JGZT00='7' WHERE YJDJH0=:NEW.YJDJH0; end if; if (:new.zxsl00<>:old.zxsl00) and (:new.sl0000-nvl(:new.cxsl00,0)<:new.zxsl00) then ErrStr:='执行数量'||to_char(:new.zxsl00)||'不能大于项目数量'||to_char(:new.sl0000)||'-冲消数量'||to_char(:new.cxsl00)||'!'; raise ecustom; end if; end if; if :new.MZZYBZ='1' and (inserting or (updating and :new.sl0000<>:old.sl0000)) and :new.sl0000>17.5 then select count(*) into Vcounter from xt_xtcs00 where name00 = 'YJ_ZLXM_ZXXY' and instr(','||trim(VALUE0)||',', ','||to_char(:new.ZLXMID)||',')>0; if Vcounter > 0 then :new.SL0000 := 17.5; end if; end if; exception when ecustom then raise_application_error(-20030,errstr||'!*'); when no_data_found then raise_application_error(-20010,'数据没有找到,'||errStr||'!*'); when others then raise_application_error(-20020, nvl(sqlerrm, '原因不明出错!*')); end; /