Mybatis 获取 clob 字段

Mybatis get clob field

我们想在基于注解的 oracle 函数调用中获取一个 clob 字段。这个函数return一个CLOB字段Oracle。 我们有这个代码:

@Select("{ #{result,  javaType=java.lang.String ,jdbcType = CLOB, mode=OUT } = call pkg_exportacion_datos.f_recupera_dgp_pac( "
        + "#{cipAuto, jdbcType=VARCHAR, mode=IN},#{idExplotacion, jdbcType=NUMERIC, mode=IN} )}")
    @Options(statementType = StatementType.CALLABLE)
@Results(
        value = {
          @Result(
              property = "result",
              column = "result",
              javaType = String.class)
        })
String getListadoDGPPaciente(String cipAuto,long idExplotacion,String result);

我们可以在 ClobTypeHandler 中调试方法 private String toString(Clob clob) throws SQLException 并且在此方法中字段 CLOB 具有有效值,但此值不是 return 在变量结果中。 内部变量 resul 设置一个空值。

有人能帮帮我吗?

谢谢。

该方法应如下所示:

@Update({
  "{#{result,javaType=java.lang.String,jdbcType=CLOB,mode=OUT}",
  "= call pkg_exportacion_datos.f_recupera_dgp_pac(",
    "#{cipAuto,jdbcType=VARCHAR,mode=IN},",
    "#{idExplotacion,jdbcType=NUMERIC,mode=IN}",
  ")}"
})
@Options(statementType = StatementType.CALLABLE)
void getListadoDGPPaciente(ParamBean param);

请注意,结果 return 作为 OUT 参数,而不是方法 return 值。
所以,你应该使用 @Update@Insert 而不是 @Select.
并且要接收 OUT 参数,方法参数必须是 Map 或像下面这样的 bean。

public class ParamBean {
  private String cipAuto;
  private long idExplotacion;
  private String result;
  // getters / setters
}

调用该方法的代码如下所示。

ParamBean param = new ParamBean();
param.setCipAuto("foo");
param.setIdExplotacion(123L);
mapper.getListadoDGPPaciente(param);
return param.getResult(); // returns the CLOB as a String