oracle oracle游标的iBatis映射

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1659329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:20:22  来源:igfitidea点击:

iBatis mapping for oracle cursor

javaoracleibatis

提问by Omnipresent

I have the following iBatis mapping for an Oracle Stored Procedure that returns a true/false value.

对于返回真/假值的 Oracle 存储过程,我有以下 iBatis 映射。

  <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?

我究竟做错了什么?我们可以不将布尔值直接存储到游标中吗?

回答by Brian

Returning a Boolean type is not supported by 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 JDBC 不支持返回布尔类型。或者更具体地说,它不能用在 Oracle 中的任何结果集中(有一个可以在 PL/SQL 中使用的布尔值,但你不能在引用游标中返回它或声明一个类型为 '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. Please consider posting the source/signature of the stored procedure - that will help with the answer.

听起来您是在说您的 ref 游标包含布尔值?如果是,您将需要返回 'Y' 或 'N' 或类似的东西。请考虑发布存储过程的来源/签名 - 这将有助于回答。

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?

and we said...

since ..., flag char(1) check (flag in ( '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')

这是给你的真正简短的汤姆:

为什么 Oracle RDBMS 没有布尔数据类型?

我们说...

因为 ..., flag char(1) check (flag in ('Y', 'N')), ...,

用于相同的目的,需要相同的空间并做相同的事情 - 我想我们觉得这是一个我们可以让他们拥有我们真正不需要的功能。

我的意思是 - 你从一个布尔值的“访问”列中得到什么?真假。我们会给您 Y/N -- 如果您想要 TRUE/FALSE,我们可以使用 DECODE(flag,'Y','TRUE','N','FALSE') 轻松完成