原创:lixx
---从UNWIREDATA 表中查询数据,如果该表中地磁状态发生改变(CARDSTATE)执行插入到MAINTABLE 表中
---根据唯一值ERID判断,如果ERID值存在,修改该条数据中的地磁状态属性(CARDSTATE)
create or replace trigger tri_dici after
update of CARDSTATE ON UNWIREDATA FOR EACH ROW
declare
V_NUM number;
BEGIN
----多次查询时,每次都将v_num设置成为0
V_NUM := 0;
----判断触发器 ERID 是否存在
select count(*) into V_NUM from MAINTABLE M where M.ERID = :new.ERID;
----如果存在立即修改CARDSTATE
if V_NUM > 0 then
update MAINTABLE M set M.CARDSTATE=:new.CARDSTATE where M.ERID=:new.erid;
else
---执行插入该数据到MAINTABLE表中
insert into MAINTABLE(UNWIREID,ERID,CARDSTATE,BERTTRYSATE,DATATIME) values(:new.unwireid,:new.erid,:new.cardstate,:new.berttrysate,sysdate);
end if;
END;
时间: 2024-10-16 02:27:31