最基本的触发器是针对表的Insert、Update、Delete这三种操作来的。
触发器可以建立在表上,也可以建立在视图上。建立在表上的触发器会在表内容发生改变时触发。建立在视图上的触发器会在视图内容改变时触发。注意,视图触发器仅会在明确对视图进行操作的SQL语句执行时才会触发,当基本表的内容发生改变而引起视图内容变化时,不会触发视图触发器。
下面是建立表触发器的代码:
下面是建立视图触发器的代码:(注意里面的instead of)
下面是建立表触发器的代码:
create or replace trigger tg_E_CONTACT
before update or insert or delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;
before update or insert or delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;
下面是建立视图触发器的代码:(注意里面的instead of)
create or replace trigger tg_E_CONTACT
before instead of update or instead of insert or instead of delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;
before instead of update or instead of insert or instead of delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;