oracle 触发器
参考大神们网址:
https://www.cnblogs.com/sharpest/p/7764662.html
https://www.cnblogs.com/sharpest/p/7764662.html
https://www.cnblogs.com/wishyouhappy/p/3665851.html
自己写的实例:(每次实时数据表插入新记录时,在table_b表中放入一条数据,放入的是刚插入实时表的一部分数据。
同时只保留table_b中最近十条数据。
注:如果begin中语句有错误会对触发表(ta_realdata)中数据产生影响。)
create or replace trigger chart_data after insert on ta_realdata for each row begin insert into ta_b values (:NEW.MONITOR_ID, :NEW.name, :NEW.code, :NEW.MONITOR_TIME); delete from ta_b where ta_b.monitor_id in (SELECT B.monitor_id FROM (SELECT A.*, ROWNUM RN FROM (select ta_b.monitor_id, MONITOR_TIME from ta_b where ta_b.code =:NEW.CODE order by MONITOR_TIME desc ) A) B WHERE RN > 10) ; END;
删除触发器:
DROP TRIGGER chart_data;