Oracle 觸發器筆記

來源:互聯網
上載者:User

create or replace trigger emp
--before 表示對操作前的觸發器
-- after 表示對操作後的觸發器

--每張表最多可建立12個觸發器
--before inset
--before insert for each row
--after insert
--after insert for each row

--before uPdate
--before uPdate for each row
--after uPdate
--after uPdate for each row

--before uPdate
--before uPdate for each row
--after uPdate
--after uPdate for each row

--執行的順序是:#1. 執行before語句級的觸發器,對於受語句影響的每一行:
-- #2. 執行級觸發器,執行DML語句
--執行after行級的觸發器
--#3. 執行 after語句級的觸發器

  before delete on aaa  --刪除操作前aaa表的觸發器
 
  for each row --對錶的每一行觸發器執行一次。如果沒有這一選項,則只對整個表執行一次。
declare

begin

     /*如果插入的任然是aaa表的話,會出現:第 1 行出現錯誤:
ORA-04091: 表 QUERY.AAA 發生了變化, 觸發器/函數不能讀它
ORA-06512: 在 "QUERY.EMP", line 4 (QUERY表示user,line表示行數,EMP表示觸發器名稱)
ORA-04088: 觸發器 'QUERY.EMP' 執行過程中出錯*/

  /*將修改前的資料插入到日誌表aaa_tmp裡去,以供監督使用*/
  insert into aaa_tmp(AID,ANAME,PRICE)
 
  values(:old.AID,:old.ANAME,:old.PRICE);--:old表示原來的資料,
                                         --:new表示插入的新資料                                  
end emp;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.