• MyBatis调用存储过程


      直接看例子:

      1、声明接口:

    public interface CustomRankingRecordMapper
    {
        void saveRankCustomInfoProcedure();
    }

      2、在CustomRankingRecord.xml定义存储过程:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.migu.reading.dao.CustomRankingRecordMapper">
    
        <!-- 调用存储过程更新自定义排行表 -->
        <update id="saveRankCustomInfoProcedure"  statementType="CALLABLE">
          {call PROC_CUSTOM_RECORD_UPDATE}
         </update>
    </mapper>

      3、在Oracle中创建存储过程:

    CREATE OR REPLACE procedure VCODE.PROC_CUSTOM_RECORD_UPDATE
    is
      cursor ACTIVITY_CUR
      is --声明显式游标
        select T.ACTIVITYID,
          T.COUNTSTARTTIME,
          T.COUNTENDTIME
        from vcode.T_INVITE_ACTIVITYINFO T
        where T.HASCOUNTTIME = 1;
      type ACTIVITY_CUR_ROW is table of ACTIVITY_CUR%ROWTYPE; --定义游标变量,该变量的类型为基于游标ACTIVITY_CUR的记录
    
      cs_invitestat SYS_REFCURSOR;
      type tp_CUSTOM_RECORD is table of T_INVITER_CUSTOM_RECORD%ROWTYPE;
      va_CUSTOM_RECORD tp_CUSTOM_RECORD;
      ACTIVITY_ID number(11,0);
      START_TIME  date;
      END_TIME    date;
    begin
      --For 循环
      for ACTIVITY_CUR_ROW in ACTIVITY_CUR
      LOOP
        ACTIVITY_ID := ACTIVITY_CUR_ROW.ACTIVITYID;
        START_TIME  := ACTIVITY_CUR_ROW.COUNTSTARTTIME;
        select TRUNC(ACTIVITY_CUR_ROW.COUNTENDTIME+1)-1/(24*3600)
        into END_TIME
        from DUAL;
    
        open cs_invitestat for select T1.INVITERMSISDN,COUNT(*) as TOTALACTIVENUMBER,max(ACTIVETIME) LASTACTIVETIME,ACTIVITYID
        from T_INVITEE_RECORD T1
        where (T1.ACTIVETIME <= END_TIME
        and T1.ACTIVETIME    >= START_TIME
        and T1.ACTIVESTATUS      = 1
        and T1.INVITEETYPE    = 0
        and T1.ACTIVITYID     = ACTIVITY_ID)
        group by ACTIVITYID,T1.INVITERMSISDN;
    
        fetch cs_invitestat bulk collect into va_CUSTOM_RECORD limit 500;
    
        forall i in 1..va_CUSTOM_RECORD.count
        merge into vcode.T_INVITER_CUSTOM_RECORD T5
        using (select * from dual)
        on (INVITERMSISDN = va_CUSTOM_RECORD(i).INVITERMSISDN AND ACTIVITYID=va_CUSTOM_RECORD(i).ACTIVITYID)
         when matched then
            update
            set TOTALACTIVENUMBER      =va_CUSTOM_RECORD(i).TOTALACTIVENUMBER,
              LASTACTIVETIME           =va_CUSTOM_RECORD(i).LASTACTIVETIME
            where T5.TOTALACTIVENUMBER!=va_CUSTOM_RECORD(i).TOTALACTIVENUMBER
          when not matched then
            insert
              (
                INVITERMSISDN,
                TOTALACTIVENUMBER,
                LASTACTIVETIME,
                ACTIVITYID
              )
              values
              (
                va_CUSTOM_RECORD(i).INVITERMSISDN,
                va_CUSTOM_RECORD(i).TOTALACTIVENUMBER,
                va_CUSTOM_RECORD(i).LASTACTIVETIME,
                va_CUSTOM_RECORD(i).ACTIVITYID
              );
            commit;
      end LOOP;
    end;
  • 相关阅读:
    异步无刷新上传文件而且上传文件能够带上參数
    利用BADI WORKORDER_INFOSYSTEM在COOIS中加入自己定义列办事处
    Printf可变參数使用
    评大北农今日复牌公告
    iOS Sprite Kit教程之申请和下载证书
    UVa 12587 Reduce the Maintenance Cost(Tarjan + 二分 + DFS)
    Python: scikit-image Blob detection
    linux命令ps aux|grep xxx详解
    复制和重命名表格--修改表注释
    md5 破解网站
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/9526348.html
Copyright © 2020-2023  润新知