日期:2014-05-16 浏览次数:20946 次
create or replace trigger aifer_rf1
before update
of obstime
on rf1 for each row
begin
:new.rainfallm10 := (
select sum(rainfall) from rf1 t2
where t2.obstime between :new.obstime-1/144 and :new.obstime
and t2.stationid=:new.stationid
)
end;
--不知道楼主需要跟新的到底是那些数据
--以上是跟新本条记录的
--ps:1/144才是10分钟
SQL> CREATE TABLE rf1(stationid number, obstime date, inserttime date, rainfall number, rainfall10 number);
Table created
SQL> insert into rf1 values(1,to_date('20130701 00:01:00','yyyymmdd HH24:MI:SS'), sysdate, 1, 0);
1 row inserted
SQL> insert into rf1 values(1,to_date('20130701 00:02:00','yyyymmdd HH24:MI:SS'), sysdate, 1, 0);
1 row inserted
SQL> create or replace trigger aifer_rf1
2 before insert
3 on rf1 for each row
4 begin
5 select sum(rainfall) into :new.rainfall10 from rf1 t2
6 where t2.obstime between :new.obstime-9/1440 and :new.obstime
7 and t2.stationid=:new.stationid
8 ;
9 end;
10 /
Trigger created
SQL> insert into