create trigger b_tri
before insert on b
for each row
declare
num number;
begin
select count(1) into num from b where id=:new.id;
if num=1 then
update a set date=:new.date where id=:new.id;
end if;
end;
/

解决方案 »

  1.   

    斑竹:
       你好!有个问题想请教。B表中本身有数据,select count(1)的值指什么,感觉上不可能为1,触发器能实现其触发条件吗,请指教。
      

  2.   

    楼主这个里面的select count(1) 里面的值是1234里面的1....这个触发器用这个来标志这个是否有数据的。
      

  3.   

    sorry,判定它是否为零,因为插入前首先触发触发器,当时还没真正插入到数据,所以统计不到是否新的记录.
    if num=0 then
    update a set date=:new.date where id=:new.id;
    end if;
      

  4.   

    土土的问: COUNT(1)的值是不是等于1,而COUNT(2)的值则为2 ?
      

  5.   

    count(1)与count(2)与count(*)三者没有分别,都是统计记录数,速度上或许count(1)比count(*)快
      

  6.   

    那num怎么还有等于0的机会。
    if num=0 then
    update a set date=:new.date where id=:new.id;
    end if;
    触发器没机会执行了!
      

  7.   

    触发器发不发生是与dml语句联系,与记录数存不存无关。
    防且if num=0 then这个条件不会影响下面语句执行,你测试一下就知道了