create or replace trigger fiber
before insert on FIBERMONITOR
for each row
declare
n Integer := 0;
begin
select count(*) into n from FIBERMONITOR_REALTIME WHERE DEPLOYADDRESS=:new.DEPLOYADDRESS;
if n=0 then
--插入语句
insert into FIBERMONITOR_REALTIME(DEPLOYADDRESS,RECTIME,STATUS,DISTANCE,WARNINGGRADE,FLAGTIME) VALUES(:new.DEPLOYADDRESS,:new.TIME,:new.STATUS,:new.DISTANCE,:new.WARNINGGRADE,:new.TIME);
else
--更新语句
update FIBERMONITOR_REALTIME set RECTIME=:new.TIME,STATUS=:new.STATUS,DISTANCE=:new.DISTANCE,WARNINGGRADE=:new.WARNINGGRADE,FLAGTIME=:new.TIME where DEPLOYADDRESS=:new.DEPLOYADDRESS;
end if;
end;