读书人

两列相加把结果放入其中一列,该怎么处

发布时间: 2012-01-08 22:48:50 作者: rapoo

两列相加把结果放入其中一列
问题是这样的,如果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
建一个触发器,谢谢阿

[解决办法]
先改变A的值然后执行
update table a set b=(select sum(a) from table where parent=a.prrent)
where prrent='你修改那条记录中parent的值'
[解决办法]
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的值没有变?
[解决办法]
在触发器中不能对基表做update 可以把计算出来的值赋给:new.COUNT_PIPE_L

SQL code
      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; 

读书人网 >oracle

热点推荐