Oracle 觸發器的簡單命令

來源:互聯網
上載者:User

標籤:for   log   基本命令   put   變數   mat   span   where   class   

-- 建立觸發器的基本命令create or replace trigger td after delete on ssbegin  dbms_output.put_line(‘刪除成功‘);end;-- 建立觸發器的基本命令create or replace trigger dd after insert on ssfor each row--沒有變數可去掉聲明--declarebegin  dbms_output.put_line(‘成功插入資料‘);end;-- 情境-:複雜的安全性檢查--raise--拋出的資料庫的錯誤--raise_application_error:拋出的是應用程的錯誤  區間(-20000 ,29999)create or replace trigger dg before insert or delete or update on ssbegin  if to_char(sysdate,‘day‘) in (‘星期六‘,‘星期日‘) or     to_number(to_char(sysdate,‘hh24‘)) not between 9 and 18      then raise_application_error(-20001,‘非工作時間禁止操作資料庫‘);  end if;end;--資料確認create or replace trigger fd before insert on scoresfor each rowbegin  if :new.math < 0   or :new.chinese < 0  or :new.english < 0  then raise_application_error(-20002,‘分數不能為零‘);  end if;end;--實現審計功能create table info(    infomation varchar2(45));-- 不及格的學生全部資訊插入info表create or replace trigger ch after update on stfor each rowbegin  if :new.math < 60   or :new.english < 60  then insert into info values(:new.math||‘,‘||:new.english);  end if;end;--資料備份和同步(此處用表示範)--建立備份表create table st_copy as select * from test1;create or replace trigger std after update on test1for each rowbegin    --更新後表st的資料備份到表st_copy裡面    update st_copy set age=:new.age,name=:new.name where id = :new.id;end;

 

Oracle 觸發器的簡單命令

聯繫我們

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