Oracle functions and procedures can be executed through Mybatis called using "<select></select>" XML descriptors. Depending on the behaviour of the procedure "<update></update>" and "<delete></delete>" descriptors can also be used. Sample of function and procedure call is presented below.
<select id="getEmpName" parameterType="java.util.Map" resultType="java.lang.String">
select getEmpName(#EMP_ID) from dual
</select>
<update id="proc_emp_update" statementType="CALLABLE" parameterType="java.util.Map" >
{call
emp_update(#{EMP_ID},#{EMP_NAME},#{DEPT_ID,jdbcType=NUMERIC},#
{DEPT_NAME,jdbcType=VARCHAR,mode=OUT})
}
</update>
The getEmpName function returns employee name. The statementType="CALLABLE" knows that is the procedure invocation. The jdbcType=NUMERIC must be provided for nullable fields during the procedure invocation. The jdbcType can be supported data type provided by Mybatis such as jdbcType=DATE for Date , jdbcType=VARCHAR for String, jdbcType=CURSOR for Cursor. mode=OUT defines that it is out parameter returned by the procedure.
No comments:
Post a Comment