简单的触发器实现

 

代码
1 ---说明:实现功能是操作某一表时,同时将该插入的数据,
2 ---保存到日志表里一份
3 ---1.测试触发器 数据表
4  create table Nrmus_triger_test
5 (
6 id varchar2(40) primary key not null,
7 data varchar2(100) null,
8 createtime timestamp null
9
10 );
11
12
13  ---2.测试触发器 日志表
14  create table Nrmus_triger_Log
15 (
16 id varchar2(40) primary key not null,
17 logs varchar2(100) null,
18 createtime timestamp null
19
20 );
21
22
23  ---3.触发器
24
25
26 create or replace trigger Nrmus_Triger
27 after insert on nrmus_triger_test
28 for each row
29 declare
30 -- local variables here
31 descr varchar2(100);
32 begin
33 descr:='您插入的不是 W-N';
34
35 if(INSTR(:new.data,'W-N',1,1)>0) then
36 descr:='您插入的是 W-N';
37 end if;
38
39 insert into Nrmus_triger_Log values
40 (sys_guid(),descr,sysdate());
41
42 end Nrmus_Triger;
43
44 ---4.测试
45
46 truncate table Nrmus_triger_Log
47 insert into Nrmus_triger_Test values(sys_guid(),'W-sssN',sysdate);
48
49 select * from Nrmus_triger_Log

 

 

 

posted @ 2010-03-26 11:07  卧龙腾飞  阅读(190)  评论(0编辑  收藏  举报