Oracle-實驗10-觸發器編程實例

1、參見教材P158/7.3.2中(1)~(3)步驟,練習在Hr模式(或用戶自己創建的表)下創建一個語句級觸發器。將所有執行正確的PL/SQL語句記錄下來。

create table emp_log( who varchar2(30), when date);

create or replace trigger ep_demo
before insert or update or delete
on emp
begin
	insert into emp_log(who,when) values(user,sysdate);
end ep_demo;
	
update emp set sal=sal*1.01;

在這裏插入圖片描述

2、參見教材p172,練習在hr模式(或用戶自己創建的表)下創建一個行級觸發器。將所有執行正確的PL/SQL語句記錄下來。

alter table emp_log add opertion varchar2(30);


create or replace trigger ep_emo
before insert or update or delete
on emp
for each row
begin
	if inserting then
	insert into emp_log(who,when,opertion) values(user,sysdate,'inserting');
	elsif updating then
	insert into emp_log(who,when,opertion) values(user,sysdate,'updating');
	elsif deleting then
	insert into emp_log(who,when,opertion) values(user,sysdate,'deleting');
	else
	insert into emp_log(who,when,opertion) values(user,sysdate,'others');
	end if;
end;


update emp set sal=sal*1.01;

select * from emp_log;

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章