首页 > 代码库 > 触发器

触发器

 

create or replace TRIGGER CAR_TEAM_LOAD_QUANTITY_TRG AFTER
  INSERT OR
  UPDATE ON ATT_TRADE
  DECLARE FK_CAR_TEAM_TASK NUMBER(15,0);--车队任务id
  TOTAL_LOAD_NUM NUMBER(15,3);                                                --已疏港量
  logid integer;
  contentstr varchar(4000);
  CURSOR numlist is
    (SELECT team.id id, SUM(trade.net) net
    FROM CAR_TEAM_DISPACHER_INFO team
    LEFT JOIN ATT_VEHICLEDISPATCH dis
    ON team.id=dis.FK_CAR_TEAM_DISPACHER_INFO_ID
    LEFT JOIN ATT_TRADE trade
    ON trade.FLEETTASKID  =dis.id
    WHERE trade.DATASTATUS=1 and trade.FLEETTASKID is not null
    GROUP BY team.ID);
  BEGIN
   FOR num_row IN numlist LOOP
   begin
    update CAR_TEAM_DISPACHER_INFO set LOAD_QUANTITY=num_row.net/1000 where id=num_row.id;
     exception
        when others then
          SELECT WEBLOG_SEQ.NEXTVAL INTO logid FROM SYS.DUAL;
              contentstr := update CAR_TEAM_DISPACHER_INFO set LOAD_QUANTITY=||num_row.net||where id=||num_row.id;
          insert into weblog (id,context) values (logid,contentstr);
   end;
  end loop;
END;

 

触发器