Oracle触发器转写成瀚高触发器
生活随笔
收集整理的這篇文章主要介紹了
Oracle触发器转写成瀚高触发器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
環境
文檔用途
詳細信息
環境
系統平臺:Microsoft Windows (64-bit) 10
版本:5.6.5
文檔用途
本文章主要介紹oracle觸發器轉換成瀚高的觸發器需要做哪些操作,主要修改哪些東西。
詳細信息
Oracle觸發器轉換為HighGoDB觸發器
1、創建觸發器函數
將Oracle觸發器的邏輯封裝成觸發器函數
2、創建觸發器
創建觸發器
創建觸發器函數
轉化為HighGoDB的觸發器,步驟:
第一步,將Oracle觸發器主邏輯封裝成HighGoDB觸發器函數
①、使用NEW替換:NEW,使用OLD 替換:OLD
②、函數返回類型為trigger最后return NEW 或者return NULL均可;
③、inserting updating deleting 替換成(TG_OP = ‘INSERT’) (TG_OP = ‘UPDATE’) (TG_OP = ‘DELETE’)
舉例:
oracle觸發器:
create or replace trigger "TRIG_ARCHIVE_HASTEN"before insert or delete or update on td_archive_hastenfor each rowdeclareisHasArchive number;beginif inserting or updating thenselect count(*)into isHasArchivefrom td_status_tempwhere businessid = :new.businessid;if (isHasArchive > 0) thenupdate td_status_tempset status = 1where businessid = :new.businessid;elseinsert into td_status_temp(businessid, status)values(:new.businessid, 1);end if;elsif deleting thenselect count(*)into isHasArchivefrom td_status_tempwhere businessid = :old.businessid;if (isHasArchive > 0) thenupdate td_status_tempset status = 1where businessid = :old.businessid;elseinsert into td_status_temp(businessid, status)values(:old.businessid, 1);end if;end if;end trig_archive_hasten;轉換成瀚高后的語法:
create or replace function TRIG_ARCHIVE_HASTEN()returns triggeras $$declareisHasArchive number;beginif(TG_OP = 'INSERT') or (TG_OP = 'UPDATE') thenselect count(*)into isHasArchivefrom td_status_tempwhere businessid = new.businessid;if (isHasArchive > 0) thenupdate td_status_tempset status = 1where businessid = new.businessid;elseinsert into td_status_temp(businessid, status)values(new.businessid, 1);end if;elsif (TG_OP = 'DELETE') thenselect count(*)into isHasArchivefrom td_status_tempwhere businessid = old.businessid;if (isHasArchive > 0) thenupdate td_status_tempset status = 1where businessid = old.businessid;elseinsert into td_status_temp(businessid, status)values(old.businessid, 1);end if;end if;return new;end;$$ language plpgsql;創建觸發器
第二步,創建觸發器
創建觸發器時,不需要replace 然后 on表直接 for each row execute procedure 加觸發器函數
create trigger TRIG_ARCHIVE_HASTENbefore insert or delete or update on td_archive_hastenfor each rowexecute procedure TRIG_ARCHIVE_HASTEN();總結
以上是生活随笔為你收集整理的Oracle触发器转写成瀚高触发器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谷歌安装ElasticSearch-he
- 下一篇: UE编辑器重要快捷键总结