您的位置:首页 > 数据库 > Oracle

mybatis调用oracle存储过程返回结果集

2017-10-25 23:24 676 查看
存储过程:

[sql] view
plain copy

CREATE OR REPLACE   

procedure P_TEST(v_cursor OUT sys_refcursor)  

as  

begin  

    OPEN v_cursor  

    FOR select POST_ID, FORUM_ID, USER_ID, POST_TITLE, POST_CONTENT, POST_TIME, TOTAL_COMMENT_COUNT from POST;  

end;  

resultMap:

[html] view
plain copy

<resultMap id="BaseResultMap" type="com.bbs.pojo.Post" >  

  <id column="POST_ID" property="postId" jdbcType="DECIMAL" />  

  <result column="FORUM_ID" property="forumId" jdbcType="DECIMAL" />  

  <result column="USER_ID" property="userId" jdbcType="DECIMAL" />  

  <result column="POST_TITLE" property="postTitle" jdbcType="VARCHAR" />  

  <result column="POST_CONTENT" property="postContent" jdbcType="VARCHAR" />  

  <result column="POST_TIME" property="postTime" jdbcType="TIMESTAMP" />  

  <result column="TOTAL_COMMENT_COUNT" property="totalCommentCount" jdbcType="DECIMAL" />  

</resultMap>  

[html] view
plain copy

<select id="testP" statementType="CALLABLE" >  

  {call P_TEST(#{v_cursor, mode=OUT, jdbcType=CURSOR, javaType=java.sql.ResultSet, resultMap=com.bbs.dao.PostMapper.BaseResultMap})}  

</select>  

注:

1. call语句左右的大括号可以去掉,但网上的好像很多都有写。

2. call语句与左右大括号间不能有空格或换行等,会报错(java.sql.SQLException: 出现不支持的 SQL92 标记: 1:)

test代码:

[java] view
plain copy

Map<String, Object> param = new HashMap<String, Object>();  

postService.testP(param);  

System.out.println((List<Post>) param.get("v_cursor"));  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle 存储