美文网首页
mybatis中调用存储过程使用游标的坑

mybatis中调用存储过程使用游标的坑

作者: 西谷haul | 来源:发表于2021-12-17 14:27 被阅读0次

    1、如下所示,首先第一点,游标返回的数据不一定,想要返回map类型的,不可以直接resultType = map,只能使用resultMap来接收
    2、select上要声明statementType="CALLABLE",不然奇奇怪怪的报错

    Mybatis中

    <resultMap type="java.util.HashMap" id="cursorMap">
    
    </resultMap>
    
    <select id="getMsgExtFields" statementType="CALLABLE" resultType="java.util.Map" databaseId="oracle">
            {call proc_msg_ext_fields(
                #{msgType, mode=IN, jdbcType=VARCHAR},
                #{encId, mode=IN, jdbcType=VARCHAR},
                #{primaryKey, mode=IN, jdbcType=VARCHAR},
                #{bizTime, mode=IN, jdbcType=TIMESTAMP},
                #{cv_1, mode=OUT, jdbcType=CURSOR,javaType=ResultSet,resultMap=cursorMap}
                )}
        </select>
    

    存储过程

    create or replace procedure proc_msg_ext_fields (
        v_msgType in varchar2,
        v_encId in varchar2,
        v_primaryKey in varchar2,
        v_bizTime in timestamp,
        cv_1 out sys_refcursor
    )
    as
    begin
            open cv_1 for select '补充数据' as name from dual;
    end;
    

    相关文章

      网友评论

          本文标题:mybatis中调用存储过程使用游标的坑

          本文链接:https://www.haomeiwen.com/subject/gesifrtx.html