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"));
[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"));
相关文章推荐
- SSM-Mybatis调用Oracle存储过程返回结果集(游标)
- mybatis调用oracle存储过程返回结果集
- MyBatis调用存储过程,含有返回结果集、return参数和output参数 .
- C#调用ORACLE存储过程返回结果集及函数
- C#调用ORACLE存储过程返回结果集及函数
- MyBatis调用存储过程,含有返回结果集、return参数和output参数
- mybatis调用oracle存储过程 返回sys_refcursor
- C#调用ORACLE存储过程返回结果集及函数
- mybatis 调用存储过程,处理返回2个不同类型的结果集
- spring调用Oracle存储过程,并返回结果集的完整实例
- MyBatis调用存储过程,含有返回结果集、return参数和output参数 .
- mybatis 调用oracle存储过程,传参、返回游标的值获取--示例
- Java调用oracle存储过程返回多个结果集
- .net调用ORACLE存储过程返回结果集及函数
- mybatis 调用 oracle 返回结果集 存储过程
- C#调用ORACLE存储过程返回结果集及函数
- MyBatis调用存储过程,含有返回结果集、return参数和output参数
- C#调用Oracle存储过程或函数返回结果集效率测试
- C#调用ORACLE存储过程返回结果集及函数
- mybatis调用oracle存储过程返回游标 读取到java的List<Map>