用mybatis 3调用pl/sql函数 [英] Calling pl/sql function with mybatis 3

查看:799
本文介绍了用mybatis 3调用pl/sql函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在pl/sql中返回布尔值的函数.我试图 直接获得该布尔值但没有成功,因此现在我正尝试将其转换为字符串(我不想修改数据库):

I have a function that returns a boolean value in pl/sql. I have tried to get directly that boolean value without success, so now I'm trying to convert it to string (I do not want to modify the database):

<parameterMap id="publicObject"   type="map">
<parameter javaType="java.lang.Object" jdbcType="VARCHAR" mode="OUT" property="result" /> 
<parameter javaType="java.lang.String" jdbcType="VARCHAR" mode="IN" property="id" /> 
</parameterMap>     

<select id="isPublicObject" parameterMap="publicObject" statementType="CALLABLE">

   <![CDATA[
    {
    declare
    v_bool BOOLEAN := TRUE;
    begin
    v_bool := PACKNAME.STF$IS_PUBLIC_OBJECT(#{id});
    #{result} := CASE WHEN v_bool THEN 'TRUE' ELSE 'FALSE' END;
    end;
    }
    ]]>

</select>

然后我得到这个异常: 查询数据库时出错.原因:org.apache.ibatis.type.TypeException:使用JdbcType OTHER为参数#2设置null时出错.尝试为此参数设置另一个JdbcType或另一个jdbcTypeForNull配置属性.原因:java.sql.SQLException :无效的列类型:1111 ####

Then I get this exception: "Error querying database. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #2 with JdbcType OTHER. Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type: 1111 ####

此代码在数据库中正常工作:

This code works correctly in the database:

declare
    v_bool BOOLEAN := TRUE;
    v_str  VARCHAR2(5);
begin
   v_bool := PACKNAME.STF$IS_PUBLIC_OBJECT('000000');
   v_str := CASE WHEN v_bool THEN 'TRUE' ELSE 'FALSE' END;
   dbms_output.put_line('result:');
   dbms_output.put_line(v_str); 
end;

推荐答案

我写了parameterType& Map示例.它适用于我的测试数据.

I wrote parameterType & Map example. It works on my test data.

XML:

<update id="isPublicObject" parameterType="map" statementType="CALLABLE">
    declare
        v_bool BOOLEAN := TRUE;
    begin
        v_bool := PACKNAME.STF$IS_PUBLIC_OBJECT(#{id});
        #{result,jdbcType=VARCHAR,mode=OUT} := CASE WHEN v_bool THEN 'TRUE' ELSE 'FALSE' END;
    end;
</update>

映射器:

public interface PLSQLMapper {
    public void isPublicObject(Map<String, Object> parameterMap);
}

主要:

PLSQLMapper mapper = session.getMapper(PLSQLMapper.class);

Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("id", 1);
mapper.isPublicObject(parameterMap);
System.out.println("result: " + parameterMap.get("result"));

这篇关于用mybatis 3调用pl/sql函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆