zoukankan      html  css  js  c++  java
  • 触发器SQL

    CREATE
        TRIGGER FUEL.HDGJcoaldayexpend1_insertTRIGGER AFTER
    INSERT
            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 ) then
    SET
        expDateChar = '' ; else
    SET
        expDateChar = char(date(expDate)) ; 
        end if ;
        
         if ( plantCode IS null ) then
    SET
        plantCode = '' ; end if ;
        
         if ( remark IS null ) then
    SET
        remark = '' ; end if ;
        
         if ( status IS null ) then
    SET
        status = '99' ; end if ; 
        
        if ( operateDate IS null ) then
    SET
        operateDateChar = '' ; else
    SET
        operateDateChar = char(date(operateDate))||' '||char(time(operateDate)); 
        end if ; 
        
        if ( operator IS null ) then
    SET
        operator = '' ; end if ; 
        
    
    
        if NOT exists(
    SELECT
        xml_id
    FROM
        fuel.jt_hdgj
    WHERE
        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.PICOALPROCESSSTATUS
    WHERE
        TABLENAME='COALDAYEXPEND1' AND
        PKID= new.id )) then
    UPDATE
        FUEL.PICOALPROCESSSTATUS
    SET
        LAST_UPDATE_DATE=new.LAST_UPDATE_DATE ,
        PROCESSTIME=new.LAST_UPDATE_DATE
    WHERE
        TABLENAME='COALDAYEXPEND1' AND
        PKID= new.id ; else
    INSERT
        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
  • 相关阅读:
    Atitit.数据库存储引擎的原理与attilax 总结
    Atitit.数据库存储引擎的原理与attilax 总结
    atitit.guice3 绑定方式打总结生成非单例对象toInstance toProvider区别 v2 pb29
    atitit.guice3 绑定方式打总结生成非单例对象toInstance toProvider区别 v2 pb29
    atitit.项目设计模式---ioc attilax总结v4 q11
    atitit.项目设计模式---ioc attilax总结v4 q11
    Atitit.attilax的 case list 项目经验 案例列表
    Atitit.attilax的 case list 项目经验 案例列表
    Atitit.python web环境的配置 attilax 总结
    Atitit.python web环境的配置 attilax 总结
  • 原文地址:https://www.cnblogs.com/chuanqiMa/p/7003223.html
Copyright © 2011-2022 走看看