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里都有值;