问题是这样的,如果a列中有数值改变,则把与改变的数值对应的parent一样的数字都与b列相加,放入b列,例如
parent a  b                    parent    a   b
1      0  1                        1     2   5
1      0  1       改变后           1     0   5
1      0  1                        1     3   5
2      0  2                        2     1   4
2      0  2                        2     1   4
建一个触发器,谢谢阿

解决方案 »

  1.   

    先改变A的值然后执行
    update table a set b=(select sum(a) from table where parent=a.prrent)
    where prrent='你修改那条记录中parent的值'
      

  2.   

    parent a  b                    parent    a  b 
    1      0  1                        1    2  5 
    1      0  1      改变后               1    0  5 
    1      0  1                        1    3  5 
    2      0  2                        2    1  4 
    2      0  2                        2    1  4 _________________________________________________
    a=3,b的值没有变?
      

  3.   

    B
    b的值是a中相同parent的所有值相加
      

  4.   

    create or replace trigger TRG_NEW_PIPE_L
      after update on pro_schedule 
      for each row
    declare
    temp_sum float;
    temp_parent   number(10);       -- local variables here
    begin
    if (:NEW.NEW_PIPE_L IS NOT NULL) THEN
           select :new.parent into temp_parent from dual;
           update pro_schedule set COUNT_PIPE_L=(select sum(NEW_PIPE_L) from pro_schedule where parent=temp_parent);
       end if;
    end TRG_NEW_PIPE_L;
    说是表发生了变化,触发器不能读,为什么啊,谢谢阿
      

  5.   

    在触发器中不能对基表做update 可以把计算出来的值赋给:new.COUNT_PIPE_L
          select :new.parent into temp_parent from dual; 
          update pro_schedule set COUNT_PIPE_L=(select sum(NEW_PIPE_L) from pro_schedule where parent=temp_parent); 
    换成
    v_b  number(10);      temp_parent := :new.parent ;
          select sum(NEW_PIPE_L)
            into : v_b
            from pro_schedule 
           where parent=temp_parent;
            :new.COUNT_PIPE_L = v_b;
               
    大概的意思是这样的,具体的你再结合你的情况看看。