--使用updating判断 create or replace trigger test_trig before update on 表1 begin if updating('字段1') then update 表2 set 字段3='<值>'; end if; if updating('字段2') then dbms_output.put_line('更新字段2'); end if; end;
create or replace trigger tri after update of 字段1 on 表1 for each row declare -- local variables here begin update 表2 set 字段3 = :new.字段1; end tri;
create or replace trigger test_trig before update on t1 begin if updating(‘a1‘) then dbms_output.put_line(‘updating a1‘); end if; if updating(‘b1‘) then dbms_output.put_line(‘updating b1‘); end if; end;SQL> update t1 set a1=9 ; updating a11 row updated.SQL> update t1 set b1=9 ; updating b11 row updated.
create or replace trigger tri after update of 字段1 on 表1 for each row declare -- local variables here begin update 表2 set 字段3 = :new.字段1; end tri;
可以这样写吗? create or replace trigger tri after update of 字段1,字段2 on 表1 for each row begin update 表2 set 字段3 = :new.字段1,表3.字段3 = :new.字段2 end;就是:update of XX1,XX2 on table
after update of 字段1,字段2 on 表1 这个是可以的update 表2 set 字段3 = :new.字段1,表3.字段3 = :new.字段2 这个是不行的,不能在一个语句处指定两张表的字段
那能这样啊 写2条update嘛
谢谢楼上的,那个表3是我写错了。呵呵。 还有个问题: CREATE OR REPLACE TRIGGER X.UP_TO_BILL AFTER UPDATE OF VFIRSTCODE2,CFIRSTID2 FOR EACH ROW begin --if(:new.dreqdate != null) --then update to_bill set dbilldate = :new.dreqdate where vcode = :new.vfirstcode2; --end if; end; 这个是成功的。 但是,我把if(:new.dreqdate != null)启用,就不行。:new.dreqdate 是有值的。:new.dreqdate != null这么判断不行吗?
CREATE OR REPLACE TRIGGER X.UP_TO_BILL AFTER UPDATE OF VFIRSTCODE2,CFIRSTID2 ON X.PO_REQUIREAPP_B REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW begin if(:new.dreqdate != null) then update to_bill set dbilldate = :new.dreqdate where vcode = :new.vfirstcode2; end if; end;这样就不行,把if判断去掉就可以。
改为 if :new.dreqdate is not null then 式下
对,对。 null的判断写错了 呵呵 我要是加两个判断呢? if ((:new.dreqdate is not null)&&(:new.VFIRSTCODE2 is not null)) then 这些行吗?
if ((:new.dreqdate is not null)and(:new.VFIRSTCODE2 is not null)) then 哈哈,可以。
create or replace trigger test_trig
before update on 表1
begin
if updating('字段1') then
update 表2 set 字段3='<值>';
end if;
if updating('字段2') then
dbms_output.put_line('更新字段2');
end if;
end;
after update of 字段1 on 表1
for each row
declare
-- local variables here
begin
update 表2 set 字段3 = :new.字段1;
end tri;
before update on t1
begin
if updating(‘a1‘) then
dbms_output.put_line(‘updating a1‘);
end if;
if updating(‘b1‘) then
dbms_output.put_line(‘updating b1‘);
end if;
end;SQL> update t1 set a1=9 ;
updating a11 row updated.SQL> update t1 set b1=9 ;
updating b11 row updated.
after update of 字段1 on 表1
for each row
declare
-- local variables here
begin
update 表2 set 字段3 = :new.字段1;
end tri;
create or replace trigger tri
after update of 字段1,字段2 on 表1
for each row
begin
update 表2 set 字段3 = :new.字段1,表3.字段3 = :new.字段2
end;就是:update of XX1,XX2 on table
这个是可以的update 表2 set 字段3 = :new.字段1,表3.字段3 = :new.字段2
这个是不行的,不能在一个语句处指定两张表的字段
还有个问题:
CREATE OR REPLACE TRIGGER X.UP_TO_BILL
AFTER UPDATE OF VFIRSTCODE2,CFIRSTID2
FOR EACH ROW
begin
--if(:new.dreqdate != null)
--then
update to_bill
set dbilldate = :new.dreqdate
where vcode = :new.vfirstcode2;
--end if;
end;
这个是成功的。
但是,我把if(:new.dreqdate != null)启用,就不行。:new.dreqdate 是有值的。:new.dreqdate != null这么判断不行吗?
CREATE OR REPLACE TRIGGER X.UP_TO_BILL
AFTER UPDATE OF VFIRSTCODE2,CFIRSTID2
ON X.PO_REQUIREAPP_B
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
begin
if(:new.dreqdate != null)
then
update to_bill
set dbilldate = :new.dreqdate
where vcode = :new.vfirstcode2;
end if;
end;这样就不行,把if判断去掉就可以。
null的判断写错了
呵呵
我要是加两个判断呢?
if ((:new.dreqdate is not null)&&(:new.VFIRSTCODE2 is not null))
then
这些行吗?
then
哈哈,可以。