问题是这样的,如果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
建一个触发器,谢谢阿
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
建一个触发器,谢谢阿
update table a set b=(select sum(a) from table where parent=a.prrent)
where prrent='你修改那条记录中parent的值'
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的值没有变?
b的值是a中相同parent的所有值相加
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;
说是表发生了变化,触发器不能读,为什么啊,谢谢阿
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;
大概的意思是这样的,具体的你再结合你的情况看看。