一个简单的触发器

来源:互联网 发布:Mac 怎么共享文件夹 编辑:程序博客网 时间:2024/05/11 00:30

---说明:实现功能是操作某一表时,同时将该插入的数据,

---保存到日志表里一份

---1.测试触发器 数据表

create table Nrmus_triger_test

(

  id varchar2(40) primary key not null,

  data varchar2(100) null,

  createtime timestamp null

 

);

 

 

---2.测试触发器  日志表

create table Nrmus_triger_Log

(

  id varchar2(40) primary key not null,

  logs varchar2(100) null,

  createtime timestamp null

 

);

 

 

---3.触发器

 

 

create or replace trigger Nrmus_Triger

  after insert on nrmus_triger_test  

  for each row

declare

  -- local variables here

  descr varchar2(100);

begin

  descr:='您插入的不是 W-N';

 

  if(INSTR(:new.data,'W-N',1,1)>0)  then

     descr:='您插入的是 W-N';

  end if;

 

  insert into Nrmus_triger_Log values

  (sys_guid(),descr,sysdate());

 

end Nrmus_Triger;

 

---4.测试

 

truncate table Nrmus_triger_Log

 insert into Nrmus_triger_Test values(sys_guid(),'W-sssN',sysdate);

 

 select * from Nrmus_triger_Log