mybatisplus调用oracle存储过程

mybatisplus调用oracle存储过程

创建一个测试的oracle存储过程

-- 创建携带返回值存储过程
CREATE OR REPLACE PROCEDURE SP_SUM_PROC_2023(number1 IN NUMBER, number2 IN NUMBER, result OUT NUMBER,result2 OUT NUMBER) is
BEGIN
result := number1 + number2;
result2 := 999;
END;

使用正常sql调用存储过程方式

-- sql窗口中调用
DECLARE res NUMBER(6); res2 NUMBER(6);
BEGIN 
   SP_SUM_PROC_2023(1, 3, res,res2); 
  dbms_output.put_line(res);
  dbms_output.put_line(res2);
END; 

使用mybatis调用方式

service层调用

    Map<String, Object> result = new HashMap<>();
    result.put("test", "asdfasdf");//这里是入参,必须输入
    result.put("errorCode", 0);// 这里是出参,随便写点东西
    result.put("errorCode2", 0);// 这里是出参,随便写点东西
    baseMapper.testTran(result);
    System.out.println("result = " + JsonUtil.toJSONString(result));

mapper接口

public interface MMapper {
    
    
    void testTran(Map<String, Object> result); // 这里没有@Param("result") 
}

mapper.xml文件

...
<select id="testTran" statementType="CALLABLE" parameterType="map">
    call SP_SUM_PROC_2023(1,2,#{errorCode,mode=OUT,jdbcType=INTEGER},#{errorCode2,mode=OUT,jdbcType=INTEGER})
</select>

mode=OUT或IN,OUT为带出的参数,IN为传入存储过程的参数

猜你喜欢

转载自blog.csdn.net/qq_27577113/article/details/134870546
今日推荐