MyBatis Oracle Stored Procedure Guide
In MyBatis, calling an Oracle stored procedure can be achieved by using either a select or an update statement to execute the stored procedure. Here is an example:
<select id="callProcedure" parameterType="map" statementType="CALLABLE">
{call PROCEDURE_NAME(
#{inputParam1, mode=IN, jdbcType=INTEGER},
#{inputParam2, mode=IN, jdbcType=VARCHAR},
#{outputParam, mode=OUT, jdbcType=INTEGER}
)}
</select>
In this example, PROCEDURE_NAME is the name of the stored procedure to be called, inputParam1 and inputParam2 are the input parameters of the stored procedure, and outputParam is the output parameter. Use a map in parameterType and specify the type and direction of the parameters in mode.
Then, execute the call to the stored procedure using MyBatis’ SqlSession in the Java code.
Map<String, Object> params = new HashMap<>();
params.put("inputParam1", 123);
params.put("inputParam2", "abcdef");
params.put("outputParam", null);
sqlSession.selectOne("callProcedure", params);
Integer outputParamValue = (Integer) params.get("outputParam");
System.out.println("Output parameter value: " + outputParamValue);
By using this method, it is possible to call an Oracle stored procedure in MyBatis and retrieve the values of output parameters.