现在有一张表Table1,其中包含字段:产品编号ID、日期D01、日产量D02。
另一张表Table2,其中包含字段:产品编号ID、月份D03、月产量D04。
现在需要编写一个触发器,当Table1执行INSERT操作后,在Table1中查找日期中月份的值等于Table2的月份,将这些记录中字段日产量D02值求和后,更新到表Table2中月产量D04中。只要表Table1中日产量一更新,表Table2中月产量马上更新。
另一张表Table2,其中包含字段:产品编号ID、月份D03、月产量D04。
现在需要编写一个触发器,当Table1执行INSERT操作后,在Table1中查找日期中月份的值等于Table2的月份,将这些记录中字段日产量D02值求和后,更新到表Table2中月产量D04中。只要表Table1中日产量一更新,表Table2中月产量马上更新。
解决方案 »
- 请教bulk collect作用。
- 如何不安装oracle的客户端用来连接服务器上的oracle数据库?
- oracle增加rbs问题,请教,谢谢
- Oracle如何提取数据库里的表信息???
- 两个9i安装方面的问题!
- 怎么把一个数据库迁移到另外一个数据库中去?
- 请问哪里可以下载到windows版的oracle8.1.7?
- 请教各位大侠一个问题,不好意思,应不属于oracle的,但和oracle有点关系
- oracle的奇怪的问题:ORA-01033: ORACLE initialization or shutdown in progress
- 有关增加外键的问题,进来看看吧!
- 请教一个统计的SQL的写法
- 函数问题
where id=:new.id and to_char(D03,'yyyymm')= to_char(:new.d02,'yyyymm');
--drop table test1;
create table TEST1
(
NUM_COL NUMBER,
CHAR_COL VARCHAR2(60)
);--drop table test2;
create table TEST2
(
NUM_COL NUMBER,
CHAR_COL VARCHAR2(60)
);
--drop procedure uptest2
create or replace procedure uptest2 as
v_num number(10);
v_char varchar2(20);
cursor gettest1 is select sum(num_col),char_col from test1 group by char_col;
begin
open gettest1;
loop
fetch gettest1 into v_num,v_char;
update test2 set num_col=v_num where char_col=v_char;
commit;
exit when gettest1%notfound;
end loop;
close gettest1;
end;
/--drop trigger updatetest2;
create or replace trigger updatetest2
after insert or update of num_col on test1 for each row
declare
v_str varchar2(200):='execute uptest2';
begin
execute immediate v_str;
commit;
end;
/