比如说当表A的一个insert,update的操作,然后自动把表A的相关字段update为一个值,但是这样就会造成死循环,如何只让触发器只执行一次。create trigger biufer_employees_department_id
before insert or update
of department_id
on employees
referencing old as old_value
new as new_value
for each row
when (new_value.department_id<>80 )
begin
:new_value.commission_pct :=0;
end; 这种自身触发只能修改 :new_value.commission_pct,我如果想修改某特定行的数据,需要加限制条件的,如果处理。加WHERE...?
before insert or update
of department_id
on employees
referencing old as old_value
new as new_value
for each row
when (new_value.department_id<>80 )
begin
:new_value.commission_pct :=0;
end; 这种自身触发只能修改 :new_value.commission_pct,我如果想修改某特定行的数据,需要加限制条件的,如果处理。加WHERE...?
如果要修改当前记录的值,条件在when里面控制就好了
如果是要修改非当前记录的其他特定记录的值,要改成表级触发器或者使用自治事务了
CREATE OR REPLACE TRIGGER trig_ac30_AAE008
AFTER insert or update of AAE008
ON AAE008_UPDATE
for each row
BEGIN
if (OLD.AAE008 <> NEW.AAE008) then
update ac30
set AAE008=:NEW.AAE008, aae010=:NEW.aae010
where AAC001 =:NEW.AAC001
AND AAE140='2';
end if
END;看到上面的触发器了吧,我想修改AC30表里的AAE140='1'时的AAE008字段的时候,触发修改同一个表AC30中的AAE140='1'时的AAE008字段
pragma autonomous_transaction;
但是编译不过去,提示 不能在这里声明
AFTER insert or update of AAE008
ON AAE008_UPDATE
for each row
when (OLD.AAE008 <> NEW.AAE008)
BEGIN
declare
pragma autonomous_transaction;begin
update ac30
set AAE008=:NEW.AAE008, aae010=:NEW.aae010
where AAC001 =:NEW.AAC001
AND AAE140='32';
commit;
end;
END;
有错误吗?
当修改 depatime 字段值的时候触发,修改其他字段的时候不触发