oracle資料庫表資料同步-觸發器

來源:互聯網
上載者:User

 create or replace
TRIGGER
"USER_TRIGGER"
AFTER INSERT
OR DELETE
OR UPDATE
ON USERS
  -- 對應三種觸發事件
FOR EACH ROW  --行級觸發器
BEGIN
  if inserting
then
    insert into USERS2
values(:new
.lid,:new.strname,:new.straddress);
  elsif deleting
then
    delete from USERS2
where USERS2.lid = :old.lid;
  elsif updating
then
    update USERS2
set USERS2.strname=:new.strname,USERS2.straddress=:new.straddress where USERS2.lid=:old
.lid;
  end if;
END;

 

1、insert/update/delete中的哪一個觸發了觸發器,可以在觸發器中使用inserting / updating / deleting 條件謂詞作判斷。

2、:new 與: old:必須是針對行級觸發器的,也就是說要使用這兩個變數的觸發器一定有for each row

這兩個變數是系統自動提供的陣列變數,:new用來記錄新插入的值,old用來記錄被刪除的值;

使用insert的時候只有:new裡有值;

使用delete的時候只有:old裡有值;

使用update的時候:new和:old裡都有值;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.