call oracle function

780 views
Skip to first unread message

artyom

unread,
Jan 10, 2011, 11:57:28 AM1/10/11
to mybatis-user
Hello,
I'm trying to migrate from ibatis 2.3.4 to myBatis 3.0 and have
encountered a difficulty of how to call oracle FUNCTION (not a
procedure).I've searched the internet, but could not found brief
explanation or a tutorial of how to implement this.

In my old ibatis code, I call an oracle function and retrieve a result
in the following way:
<parameterMap id="exchRatesParams" class="java.util.HashMap">
<parameter property="txnDate" jdbcType="DATE"
javaType="java.sql.Date" mode="IN"/>
<parameter property="exchType" jdbcType="VARCHAR"
javaType="java.lang.String" mode="IN"/>
<parameter property="exchRatesList"
javaType="OBJECT"
jdbcType="ARRAY"
typeName="TBL_EXCH_RATE"
mode="OUT"
typeHandler="com.zzz.ex.ExchRateTypeHandler"/>
</parameterMap>

<procedure id="getExchRates" parameterMap="exchRatesParams">
<![CDATA[
{call
declare
v_exch_rates_tbl TBL_EXCH_RATE;
begin
v_exch_rates_tbl :=
EXCH_RATES.GET_DAILY_EXCHANGE_RATES(?, ?);
? := v_exch_rates_tbl;
end
}
]]>
</procedure>

TBL_EXCH_RATE is an oracle user-defined type which is table of other
user-defined type called T_EXCH_RATE.
How can I implement the same logic using myBatis 3?
Please, help me!
Thanks in advance

Guy Rouillier

unread,
Jan 10, 2011, 6:18:44 PM1/10/11
to mybati...@googlegroups.com

If what you show worked for you in iBATIS 2, then a translation of it
should work in MyBatis 3. In place of <procedure> you would use a
<select statementType="CALLABLE">. In place of a parameter map, you
would substitute your parameter definitions inline where you currently
have a question mark (?).

Did you try this and it did not work? If so, what errors did you encounter?

--
Guy Rouillier

artyom

unread,
Jan 11, 2011, 2:28:06 AM1/11/11
to mybatis-user
Thanks for your response.
I've figured out what was wrong in my code. I've made a mistake while
translating to the syntax of myBatis 3. Instead of "jdbcTypeName"
inside of "out" parameter it was written "typeName" (the way it was in
iBATIS 2).
The full code is as follows:
<select id="exchRatesParams" parameterType="java.util.HashMap"
statementType="CALLABLE">
<![CDATA[
{call
declare
v_exch_rates_tbl TBL_EXCH_RATE;
begin
v_exch_rates_tbl :=
EXCH_RATES.GET_DAILY_EXCHANGE_RATES(#{txnDate,

jdbcType=DATE,

javaType=java.sql.Date,

mode=IN},

#{exchType,

jdbcType=VARCHAR,

javaType=java.lang.String,

mode=IN});
#{exchRatesList,
jdbcType=ARRAY,
javaType=OBJECT,
jdbcTypeName=TBL_EXCH_RATE,
mode=OUT,
typeHandler=com.zzz.ex.ExchRateTypeHandler} :=
v_exch_rates_tbl;
end
}
]]>
</select>

Kind Regards,
Artyom
Reply all
Reply to author
Forward
0 new messages