简体   繁体   English

oracle游标的iBatis映射

[英]iBatis mapping for oracle cursor

I have the following iBatis mapping for an Oracle Stored Procedure that returns a true/false value. 我有一个Oracle存储过程的以下iBatis映射,它返回一个true / false值。

  <resultMap id="isAuthorizedResult" class="java.lang.Boolean">
    <result property="isAuthorized" column="isAuthorized"/>
  </resultMap>
  <parameterMap id="isAuthorizedCall" class="map">
    <parameter property="prgType" jdbcType="String" javaType="java.lang.String" mode="IN"/>
    <parameter property="parCode" jdbcType="String" javaType="java.lang.String" mode="IN"/>
    <parameter property="userId" jdbcType="String" javaType="java.lang.String" mode="IN"/>
    <parameter property="Result0" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="isAuthorizedResult"/>
  </parameterMap>
<procedure id="isAuthorized" parameterMap="isAuthorizedCall">{call chk_user_ocpncy (?,?,?,?) }</procedure>

I call the mapping from my Java code like this: 我从我的Java代码中调用映射,如下所示:

getSqlMapClientTemplate().queryForObject("reexamination.isAuthorized", paramMap);

However, I get the following error... 但是,我收到以下错误...

Fail to convert to internal representation; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:

What am I doing wrong? 我究竟做错了什么? can we not store a boolean value directly into the cursor? 我们不能直接将一个布尔值存储到游标中吗?

Returning a Boolean type is not supported by Oracle JDBC . Oracle JDBC不支持返回布尔类型。 Or more specifically, it can't be used in any result set in Oracle (there is a Boolean that can be used in PL/SQL, but you can't return it in a ref cursor or declare a column of being type 'Boolean'. 或者更具体地说,它不能在Oracle的任何结果集中使用(有一个可以在PL / SQL中使用的布尔值,但是你不能在ref游标中返回它或声明一个类型为'Boolean的列”。

It sounds like you are saying that your ref cursor contains boolean? 听起来你说你的引用游标包含布尔值? If yes, you will need to return 'Y' or 'N' or something similar. 如果是,您将需要返回'Y'或'N'或类似的东西。 Please consider posting the source/signature of the stored procedure - that will help with the answer. 请考虑发布存储过程的源/签名 - 这将有助于解决问题。

http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#34_05 http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#34_05

Tom Kyte's traditionally cheeky response : You Asked Tom Kyte传统的厚颜无耻的回应 :你问过

Here's a real short one for you Tom: 汤姆:这是一个真正的短篇小说:

Why doesn't Oracle RDBMS have a boolean datatype? 为什么Oracle RDBMS没有布尔数据类型?

and we said... 我们说......

since ..., flag char(1) check (flag in ( 'Y', 'N' )), ..., 因为...,标志字符(1)检查(标记在('Y','N')),...,

serves the same purpose, requires the same amount of space and does the same thing - I guess we feel this is a feature we can let them have that we really don't need. 服务于同样的目的,需要相同的空间并做同样的事情 - 我想我们觉得这是一个我们可以让他们拥有我们真正不需要的功能。

I mean - what do you get back from a column in "access" that is a boolean? 我的意思是 - 你从“访问”中的一个列中得到什么,这是一个布尔值? TRUE / FALSE. 真假。 We'll give you Y/N -- if you would like TRUE/FALSE, we can accomplish that easily with DECODE(flag,'Y','TRUE','N','FALSE') 我们会给你Y / N - 如果你想要TRUE / FALSE,我们可以用DECODE(旗帜,'Y','TRUE','N','FALSE')轻松完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM