create or replace trigger i_Scp_Stat_Mininfo_trig
after insert on i_scp_stat_mininfo
for each row
declare
result number;
datetime varchar2(20);
scpname varchar2(30);
newcaps NUMBER(10,2);
oldcaps number(10,2);
begin
datetime := substr(:new.DATETIME,0,10);
scpname := :new.scpname;
newcaps := :new.caps;
select count(*) into result from i_scp_stat_dayinfo where DATETIME = datetime and SCPNAME = scpname;
if result = 0
then
begin
insert into i_scp_stat_dayinfo values(scpname,newcaps,datetime);
end;
end if;
if result = 1
then
begin
select caps into oldcaps from i_scp_stat_dayinfo where DATETIME = datetime and SCPNAME = scpname;
if newcaps > oldcaps
then
update i_scp_stat_dayinfo set caps = newcaps where DATETIME = datetime and SCPNAME = scpname;
end if;
end;
end if;
end;
after insert on i_scp_stat_mininfo
for each row
declare
result number;
datetime varchar2(20);
scpname varchar2(30);
newcaps NUMBER(10,2);
oldcaps number(10,2);
begin
datetime := substr(:new.DATETIME,0,10);
scpname := :new.scpname;
newcaps := :new.caps;
select count(*) into result from i_scp_stat_dayinfo where DATETIME = datetime and SCPNAME = scpname;
if result = 0
then
begin
insert into i_scp_stat_dayinfo values(scpname,newcaps,datetime);
end;
end if;
if result = 1
then
begin
select caps into oldcaps from i_scp_stat_dayinfo where DATETIME = datetime and SCPNAME = scpname;
if newcaps > oldcaps
then
update i_scp_stat_dayinfo set caps = newcaps where DATETIME = datetime and SCPNAME = scpname;
end if;
end;
end if;
end;