我有3个表
create table length (
coil_id number,
a number
);
create table tab1 (
mother_id number,
b number
);
create table tab2(
id number,
c number
);我想在length 表有新的数据插入时,将length表中coil_id的第2位与tab1中mother_id第2位相同的a字段的数据求和写入到tab2中
(length中id字段不是主键,可以重复,也就是length中有数据插入时,原来就有同样id的数据)
create table length (
coil_id number,
a number
);
create table tab1 (
mother_id number,
b number
);
create table tab2(
id number,
c number
);我想在length 表有新的数据插入时,将length表中coil_id的第2位与tab1中mother_id第2位相同的a字段的数据求和写入到tab2中
(length中id字段不是主键,可以重复,也就是length中有数据插入时,原来就有同样id的数据)
求sum(a+b)
设这样吗? 没看明白
BEFORE INSERT on length for each row
declare
v_id varchar2(10);
v_sum1 number;
v_sum2 number;
begin
v_id:=substr(to_char(:NEW.coil_id),2,1);
select sum(nvl(b,0)) into v_sum1 from tab1 where substr(to_char(mother_id),2,1)= v_id;
insert into tab2
select :NEW.coil_id,v_sum1+sum(nvl(a,0))
from length where substr(to_char(coil_id),2,1)=v_id;end;
我想在length 表有新的数据插入时,将length表中coil_id的第2位与tab1中mother_id第2位相同的a字段的数据求和写入到tab2中
不明白是要求什么之和