3、 在employees_copy表上建立语句触发器,在触发器中填充employees_log 表。
Create or replace trigger biud_employee_copy Before insert or update or delete On employees_copy Begin Insert into employees_log( Who,when) Values( user, sysdate); End; /
|
4、 测试
update employees_copy set salary= salary*1.1; select *from employess_log;
|
5、 确定是哪个语句起作用?
即是INSERT/UPDATE/DELETE中的哪一个触发了触发器?
可以在触发器中使用INSERTING / UPDATING / DELETING 条件谓词,作判断:
begin if inserting then ----- elsif updating then ----- elsif deleting then ------ end if; end; if updating(‘COL1’) or updating(‘COL2’) then ------ end if;
|
[试验]
1、 修改日志表
alter table employees_log add (action varchar2(20));
|
2、 修改触发器,以便记录语句类型。
以下是引用片段:
Create or replace trigger biud_employee_copy Before insert or update or delete On employees_copy Declare L_action employees_log.action%type; Begin if inserting then l_action:=’Insert’; elsif updating then l_action:=’Update’; elsif deleting then l_action:=’Delete’; else raise_application_error(-20001,’You should never ever get this error.’); Insert into employees_log( Who,action,when) Values( user, l_action,sysdate); End; /
|
3、 测试
以下是引用片段:
insert into employees_copy( employee_id, last_name, email, hire_date, job_id) values(12345,’Chen’,’Donny@hotmail’,sysdate,12); select *from employees_log
|
阅读(206) | 评论(0) | 转发(0) |