首页 > 代码库 > 触发器SQL

触发器SQL

CREATE    TRIGGER FUEL.HDGJcoaldayexpend1_insertTRIGGER AFTERINSERT        ON        FUEL.coaldayexpend1 REFERENCING NEW AS new FOR EACH ROW MODE DB2SQL                 begin atomic                 declare expDate TIMESTAMP ; declare plantCode VARCHAR(32) ;        declare powerQuan DOUBLE ; declare heatQuan DOUBLE ; declare netQuan DOUBLE ;        declare beltQuan DOUBLE ; declare beltAdjustQuan DOUBLE ; declare powerExpQuan        DOUBLE ; declare heatExpQuan DOUBLE ; declare otherExpQuan DOUBLE ; declare        scheduleQuan DOUBLE ; declare remark VARCHAR(512); declare status VARCHAR(16) ;        declare operateDate TIMESTAMP ; declare operator VARCHAR(50) ; declare        expDateChar VARCHAR(32) ; declare operateDateChar VARCHAR(32) ; declare xml_id        BIGINT;SET    ( expDate,    plantCode,    powerQuan,    heatQuan,    netQuan,    beltQuan,    beltAdjustQuan,    powerExpQuan,    heatExpQuan,    otherExpQuan,    scheduleQuan,    remark,    status,    operateDate,    operator ) = ( new.expDate,    new.plantCode,    new.powerQuan,    new.heatQuan,    new.netQuan,    new.beltQuan,    new.beltAdjustQuan,    new.powerExpQuan,    new.heatExpQuan,    new.otherExpQuan,    new.scheduleQuan,    new.remark,    new.status,    new.operateDate,    new.operator );     if ( expDate IS null ) thenSET    expDateChar = ‘‘ ; elseSET    expDateChar = char(date(expDate)) ;     end if ;         if ( plantCode IS null ) thenSET    plantCode = ‘‘ ; end if ;         if ( remark IS null ) thenSET    remark = ‘‘ ; end if ;         if ( status IS null ) thenSET    status = 99 ; end if ;         if ( operateDate IS null ) thenSET    operateDateChar = ‘‘ ; elseSET    operateDateChar = char(date(operateDate))|| ||char(time(operateDate));     end if ;         if ( operator IS null ) thenSET    operator = ‘‘ ; end if ;         if NOT exists(SELECT    xml_idFROM    fuel.jt_hdgjWHERE    tablename = coaldayexpend1 AND    hdgj_id = char(new.id)) then    INSERT    INTO platform.DATA_COALDAYEXPEND1(timemark,    itemid,    datadetail)VALUES    (char(current date) ||  ||char( current time ),    plantCode,    <CoalDayExpendLiang> <expDate>||expDateChar||</expDate>     <plantCode>||plantCode||</plantCode>    <powerQuan>||fuel.doutochar(powerQuan)||</powerQuan>    <heatQuan>||fuel.doutochar(heatQuan)||</heatQuan>    <netQuan>||fuel.doutochar(netQuan)||</netQuan>    <beltQuan>||fuel.doutochar(beltQuan)||</beltQuan>    <beltAdjustQuan>||fuel.doutochar(beltAdjustQuan)||</beltAdjustQuan>    <powerExpQuan>||fuel.doutochar(powerExpQuan)||</powerExpQuan>    <heatExpQuan>||fuel.doutochar(heatExpQuan)||</heatExpQuan>    <otherExpQuan>||fuel.doutochar(otherExpQuan)||</otherExpQuan>    <scheduleQuan>||fuel.doutochar(scheduleQuan)||</scheduleQuan>    <status>||status||</status> <remark>||remark||</remark>    <operateDate>||operateDateChar||</operateDate>    <operator>||operator||</operator> </CoalDayExpendLiang> );SET    (xml_id) = (SELECT    identity_val_local()FROM    sysibm.sysdummy1) ;INSERT    INTO fuel.jt_hdgj(tablename,    xml_id,    hdgj_id)VALUES    (coaldayexpend1,    xml_id,    to_char(new.id)); end if;         if(exists(SELECT    *FROM    FUEL.PICOALPROCESSSTATUSWHERE    TABLENAME=COALDAYEXPEND1 AND    PKID= new.id )) thenUPDATE    FUEL.PICOALPROCESSSTATUSSET    LAST_UPDATE_DATE=new.LAST_UPDATE_DATE ,    PROCESSTIME=new.LAST_UPDATE_DATEWHERE    TABLENAME=COALDAYEXPEND1 AND    PKID= new.id ; elseINSERT    INTO FUEL.PICOALPROCESSSTATUS (TABLENAME,    PKID,    PROCESS,    LAST_UPDATE_DATE,    PROCESSTIME)VALUES    (COALDAYEXPEND1,    new.id,    已处理,    new.LAST_UPDATE_DATE,    new.LAST_UPDATE_DATE); end if; END

 

触发器SQL