繁体   English   中英

Spring Jdbc的Oracle SQL函数返回类型

[英]Oracle Sql Function return type for Spring Jdbc

我有一个sql函数(对sql不了解)

CREATE OR REPLACE FUNCTION RATELIMIT_OWN.Get_Conns_By_Login_IP_CallerId (p_yyyymm VARCHAR2, p_login VARCHAR2, p_framed_ip VARCHAR2, p_caller_id VARCHAR2 )
    RETURN CONNECTION_RECORD_4_IPV6_TABLE PIPELINED IS

TYPE        ref0 IS REF CURSOR;
cur0        ref0;
v_where_clause VARCHAR2(512);

out_rec     CONNECTION_RECORD_4_IPV6 := connection_record_4_ipv6(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

BEGIN

  if p_login is not NULL
  then
    v_where_clause := 'where login=''' || p_login || '''';
    if p_framed_ip is not NULL
    then
      v_where_clause := v_where_clause || ' and framed_ip=''' || p_framed_ip || '''';
    end if;
    if p_caller_id is not NULL
    then
      v_where_clause := v_where_clause || ' and caller_id=''' || p_caller_id || '''';
    end if;
  else
    v_where_clause := '';
    if p_framed_ip is not NULL
    then
      v_where_clause := 'where framed_ip=''' || p_framed_ip || '''';
      if p_caller_id is not NULL
      then
        v_where_clause := v_where_clause || ' and caller_id=''' || p_caller_id || '''';
      end if;
    else
      if p_caller_id is not NULL
      then
        v_where_clause := 'where caller_id=''' || p_caller_id || '''';
      end if;    
    end if;
  end if;

  OPEN cur0 FOR
    'SELECT login,acct_ts_start,acct_ts_stop,cause,duration,inb,outb,framed_ip,caller_id,called_id,nas_id,radius_type,format_ipv6_prefix(framed_ipv6_prefix),format_ipv6_prefix(delegated_ipv6_prefix) from ticket partition (TICKETS_P' || p_yyyymm || ') ' || v_where_clause;

   LOOP
   FETCH cur0 INTO out_rec.login, out_rec.acct_start, out_rec.acct_stop, out_rec.cause, out_rec.duration, out_rec.in_bytes, out_rec.out_bytes, out_rec.public_ip, out_rec.caller_id, out_rec.called_id, out_rec.nas_id, out_rec.radius_type, out_rec.framed_ipv6_prefix, out_rec.delegated_ipv6_prefix;
   EXIT WHEN cur0%NOTFOUND;
   PIPE ROW(out_rec);
  END LOOP;
  CLOSE cur0;

RETURN;
END Get_Conns_By_Login_IP_CallerId;
/

我正在使用Spring JDBC模板调用此函数

 SimpleJdbcCall caller = new SimpleJdbcCall(this.jdbcTemplateMartinique).withSchemaName("RATELIMIT_OWN").withFunctionName("Get_Conns_By_Login_IP_CallerId").withReturnValue()
            .declareParameters(new SqlParameter(P_YYYYMM, Types.VARCHAR))
            .declareParameters(new SqlParameter(P_LOGIN, Types.VARCHAR))
            .declareParameters(new SqlParameter(P_FRAMED_IP, Types.VARCHAR))
            .declareParameters(new SqlParameter(P_CALLER_ID, Types.VARCHAR));

    SearchAccountBean resultBean = null;

    SqlParameterSource paramMap = new MapSqlParameterSource().addValue(P_YYYYMM, searchAccountBean.getDate(), Types.VARCHAR).addValue(P_LOGIN, searchAccountBean.getLogin(), Types.VARCHAR)
            .addValue(P_FRAMED_IP, searchAccountBean.getIpAddress(), Types.VARCHAR).addValue(P_CALLER_ID, searchAccountBean.getCaller(), Types.VARCHAR);
    caller.compile();
    Object result = caller.executeFunction(Object.class, paramMap);

现在,它抛出无效的列类型1111。我调试并发现它正在返回“ SQL类型1111返回”。

我想知道如何在Java中检索函数结果的值。

看起来我刚刚通过为输出参数注册“类型处理程序”解决了一些问题。 技巧是为SqlOutParameter注册SqlReturnType-请参阅SqlOutParamater的构造函数。 该接口具有方法getTypeValue(),使您可以处理来自Oracle STRUCT的信息,这很可能是您的类型在JDBC中的表示形式。

您可以在此处找到更多详细信息: http : //rostislav-matl.blogspot.cz/2012/10/accessing-oracle-user-defined-type-with.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM