
Invocar Funcion Oracle Tipo PIPELINED en JAVA
Publicado por Nelson (1 intervención) el 29/08/2024 16:39:02
Buenas...A continuación les describo mi problemita...
Intento invocar en JAVA una función de oracle Tipo PIPELINED.
a) Encabezado de la función:
create or replace FUNCTION SF_GET_HISTO_FACTURACION (VANNO NUMBER, VMES NUMBER,VMESFIN NUMBER,VNISE NUMBER, VMEDIDOR NUMBER, VLOCALIZACION NUMBER) RETURN TIPO_TABLA_HISTO_FACTURACION PIPELINED AS
b) Los datos se recorren con un cursor...
open CUR_HISTORICO_ANOMES(VANNO, VMES);
LOOP
FETCH CUR_HISTORICO_ANOMES BULK COLLECT INTO nt_src_data LIMIT 5000;
FOR i IN 1 .. nt_src_data.COUNT LOOP
PIPE ROW(TIPO_FILA_HISTO_FACTURACION(
nt_src_data(i).ANO_FACTY,
nt_src_data(i).MES_FACT,
nt_src_data(i).ABONADO,
nt_src_data(i).LOCALIZA,.....
c) Invocó la función desde sqlDeveloper así
"..select * from table (sf_get_histo_facturacion(2024,2,2,367195,NULL,NULL)); ..."
y me devuelve un resulset.
***************************************************
HASTA AQUI TODO BIEN...
***************************************************
>>> PROBLEMA...<<<<
d) En java invoco la función así:
private final static String SF_GET_HISTO_FACTURACION = "select * from table SF_GET_HISTO_FACTURACION(?,?,?,?,?,?));";
@Override
public List<ConsultaFacturacionHistoricoDTO> consultaPorMesAnio(Integer anio, Integer mesInicio, Integer mesFin,
Integer nise, Integer medidor, Integer localizacion) {
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource)
.withFunctionName(SF_GET_HISTO_FACTURACION)
.withoutProcedureColumnMetaDataAccess()
.declareParameters(new SqlOutParameter("RETURN", this.ORACLE_REF_CURSOR),
new SqlParameter("VANNO", Types.NUMERIC),
new SqlParameter("VMES", Types.NUMERIC),
new SqlParameter("VMESFIN", Types.NUMERIC),
new SqlParameter("VNISE", Types.NUMERIC),
new SqlParameter("VMEDIDOR", Types.NUMERIC),
new SqlParameter("VLOCALIZACION", Types.NUMERIC)).returningResultSet("return", (r,i)->{
ConsultaFacturacionHistoricoDTO c = new ConsultaFacturacionHistoricoDTO();
c.setAnoFacty(r.getInt("ANO_FACTY"));
return c;
});
MapSqlParameterSource in = new MapSqlParameterSource();
Integer periodo =0;
in.addValue("VANNO", anio);
in.addValue("VMES", mesInicio);
in.addValue("VMESFIN", mesFin);
in.addValue("VNISE", nise);
in.addValue("VMEDIDOR", medidor);
in.addValue("VLOCALIZACION", localizacion);
List<ConsultaFacturacionHistoricoDTO> resultados =jdbcCall.executeFunction(List.class, in);
return resultados;
}
e) y me despliega el ERROR:
"..Error 500: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call SELECT * FROM TABLE (SF_GET_HISTO_FACTURACION(?,?,?,?,?,?));(?, ?, ?, ?, ?, ?)}]; SQL state [99999]; error code [17041]; Falta el parámetro IN o OUT en el índice:: 8; nested exception is java.sql.SQLException: Falta el parámetro IN o OUT en el índice:: 8"..."
El punto es que SIN EL PIPELINED en la función NO ME DA ESTE ERROR... Corre bien... Pero lo ocupo con este PIPELINED
Saludos,
Intento invocar en JAVA una función de oracle Tipo PIPELINED.
a) Encabezado de la función:
create or replace FUNCTION SF_GET_HISTO_FACTURACION (VANNO NUMBER, VMES NUMBER,VMESFIN NUMBER,VNISE NUMBER, VMEDIDOR NUMBER, VLOCALIZACION NUMBER) RETURN TIPO_TABLA_HISTO_FACTURACION PIPELINED AS
b) Los datos se recorren con un cursor...
open CUR_HISTORICO_ANOMES(VANNO, VMES);
LOOP
FETCH CUR_HISTORICO_ANOMES BULK COLLECT INTO nt_src_data LIMIT 5000;
FOR i IN 1 .. nt_src_data.COUNT LOOP
PIPE ROW(TIPO_FILA_HISTO_FACTURACION(
nt_src_data(i).ANO_FACTY,
nt_src_data(i).MES_FACT,
nt_src_data(i).ABONADO,
nt_src_data(i).LOCALIZA,.....
c) Invocó la función desde sqlDeveloper así
"..select * from table (sf_get_histo_facturacion(2024,2,2,367195,NULL,NULL)); ..."
y me devuelve un resulset.
***************************************************
HASTA AQUI TODO BIEN...
***************************************************
>>> PROBLEMA...<<<<
d) En java invoco la función así:
private final static String SF_GET_HISTO_FACTURACION = "select * from table SF_GET_HISTO_FACTURACION(?,?,?,?,?,?));";
@Override
public List<ConsultaFacturacionHistoricoDTO> consultaPorMesAnio(Integer anio, Integer mesInicio, Integer mesFin,
Integer nise, Integer medidor, Integer localizacion) {
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource)
.withFunctionName(SF_GET_HISTO_FACTURACION)
.withoutProcedureColumnMetaDataAccess()
.declareParameters(new SqlOutParameter("RETURN", this.ORACLE_REF_CURSOR),
new SqlParameter("VANNO", Types.NUMERIC),
new SqlParameter("VMES", Types.NUMERIC),
new SqlParameter("VMESFIN", Types.NUMERIC),
new SqlParameter("VNISE", Types.NUMERIC),
new SqlParameter("VMEDIDOR", Types.NUMERIC),
new SqlParameter("VLOCALIZACION", Types.NUMERIC)).returningResultSet("return", (r,i)->{
ConsultaFacturacionHistoricoDTO c = new ConsultaFacturacionHistoricoDTO();
c.setAnoFacty(r.getInt("ANO_FACTY"));
return c;
});
MapSqlParameterSource in = new MapSqlParameterSource();
Integer periodo =0;
in.addValue("VANNO", anio);
in.addValue("VMES", mesInicio);
in.addValue("VMESFIN", mesFin);
in.addValue("VNISE", nise);
in.addValue("VMEDIDOR", medidor);
in.addValue("VLOCALIZACION", localizacion);
List<ConsultaFacturacionHistoricoDTO> resultados =jdbcCall.executeFunction(List.class, in);
return resultados;
}
e) y me despliega el ERROR:
"..Error 500: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call SELECT * FROM TABLE (SF_GET_HISTO_FACTURACION(?,?,?,?,?,?));(?, ?, ?, ?, ?, ?)}]; SQL state [99999]; error code [17041]; Falta el parámetro IN o OUT en el índice:: 8; nested exception is java.sql.SQLException: Falta el parámetro IN o OUT en el índice:: 8"..."
El punto es que SIN EL PIPELINED en la función NO ME DA ESTE ERROR... Corre bien... Pero lo ocupo con este PIPELINED
Saludos,
Valora esta pregunta


0