create or replace trigger aaa before update on a for each row begin insert into b(id) values (:new.id); end trg_a;
对不起,我表达得不正确: 表a (ID number not null, M varchar2(20) not null, N varchar2(30) not null, X varchar3(10) not null, ...) 表b (ID number not null,..)在表a中并不只是三个字段,我现在是要只有这两个字段真实的改变了才触发的。
create or replace trigger aaa before update of "M","N" on a for each row begin insert into b(id) values (:new.id); end trg_a;
这样的话,要是一条SQL命令>update a set m='s',n='d' where id=1; 但是我发现当m和n的值原来就是's'和'd'时,update语句执行后也会插入一条记录到b表。 是不是只有这种办法了: if exists(select 1 from sherc_res where m<>:new.m and id=:new.id) then insert into b(id,field) values (:new.id,m); end if if exists(select 1 from sherc_res where n<>:new.n and id=:new.id) then insert into b(id,field) values (:new.id,n); end if但是,即使是这样,编译也通不过阿...(报错说exists只能在sql语句中使用),郁闷啊!
哦,错了,表sherc_res应该是 aif exists(select 1 from a where m<>:new.m and id=:new.id) then insert into b(id,field) values (:new.id,m); end if if exists(select 1 from a where n<>:new.n and id=:new.id) then insert into b(id,field) values (:new.id,n); end if
to jiang_zhongping(一剑飞雪): 还请指教!谢谢!
create or replace trigger trg_a before update on a for each row begin if :new.M <>:old.M or :new.N<> :old.N then insert into b(id) values (:new.id); end if; end trg_a; /
before update on a
for each row
begin
insert into b(id) values (:new.id);
end trg_a;
表a (ID number not null,
M varchar2(20) not null,
N varchar2(30) not null,
X varchar3(10) not null,
...)
表b (ID number not null,..)在表a中并不只是三个字段,我现在是要只有这两个字段真实的改变了才触发的。
before update of "M","N" on a
for each row
begin
insert into b(id) values (:new.id);
end trg_a;
但是我发现当m和n的值原来就是's'和'd'时,update语句执行后也会插入一条记录到b表。
是不是只有这种办法了:
if exists(select 1 from sherc_res where m<>:new.m and id=:new.id) then
insert into b(id,field) values (:new.id,m);
end if
if exists(select 1 from sherc_res where n<>:new.n and id=:new.id) then
insert into b(id,field) values (:new.id,n);
end if但是,即使是这样,编译也通不过阿...(报错说exists只能在sql语句中使用),郁闷啊!
insert into b(id,field) values (:new.id,m);
end if
if exists(select 1 from a where n<>:new.n and id=:new.id) then
insert into b(id,field) values (:new.id,n);
end if
还请指教!谢谢!
create or replace trigger trg_a
before update on a
for each row
begin
if :new.M <>:old.M or :new.N<> :old.N then
insert into b(id) values (:new.id);
end if;
end trg_a;
/