乙個簡單的ORACLE觸發器

2021-05-23 10:20:40 字數 1590 閱讀 3938

開發是用到的乙個觸發器,現學現賣,功能實現了,留此記錄以便日後查閱。

create or replace trigger trigger_oa_mail_user

after delete or insert or update on oa_mail_user

for each row

begin

if inserting then

--insert觸發

if :new.notread = 1 then

if :new.mailstatus = 1 and :new.mail_id is not null then

update oa_system_remind t set t.newmail = t.newmail+1 where t.userid = :new.emp_id;

end if;

end if;

elsif updating then

--update觸發

if :new.notread = 1 then

if (:old.mailstatus = 1) and (:new.mailstatus = 10 or :new.mailstatus = 11) then

update oa_system_remind t set t.newmail = t.newmail-1 where t.userid = :new.emp_id;

elsif :new.mailstatus = 1 and :old.mailstatus != 1 then

update oa_system_remind t set t.newmail = t.newmail+1 where t.userid = :new.emp_id;

elsif :new.mailstatus != 1 and :old.mailstatus = 1 then

update oa_system_remind t set t.newmail = t.newmail-1 where t.userid = :new.emp_id;

elsif :old.notread != 1 then

update oa_system_remind t set t.newmail = t.newmail+1 where t.userid = :new.emp_id;

end if;

elsif :new.notread != 1 and :old.notread = 1 then

update oa_system_remind t set t.newmail = t.newmail-1 where t.userid = :new.emp_id;

end if;

elsif deleting then

--delete觸發

if :old.notread = 1 then

if :old.mailstatus = 1 then

update oa_system_remind t set t.newmail = t.newmail-1 where t.userid = :old.emp_id;

end if;

end if;

end if;

end;

oracle的乙個簡單的觸發器

create or replace trigger trg tz xs kouyacaiqingdan 台賬扣押財務觸發器 刑事子表 after insert or update on xs kouyawupinqingdan for each row declare begin if insert...

Oracle觸發器的乙個簡單例子

使用者狀態變成離職狀態,系統配置表被觸發,修改配置表狀態 create or replace trigger basedb userleft before update or delete on basedb users for each row declare local variables he...

乙個簡單的觸發器

觸發器是與表有關的資料庫物件,在滿足定義條件時觸發,並執行觸發器中定義的語句集合。觸發器的特性 1 有begin end體,begin end 之間的語句可以寫的簡單或者複雜 2 什麼條件會觸發 i d u 3 什麼時候觸發 在增刪改前或者後 4 觸發頻率 針對每一行執行 5 觸發器定義在表上,附著...