Function in Postgresql - Problem with refcursor

0

Hello everyone I want to know if my code is well raised, it is for me to report but it returns me alone and I tried with the fetch all in ""; commit; but it still does not give me anything back.

.... CODE .....

{
CREATE OR REPLACE FUNCTION gf.stp_infraccion_admi_report04(opcion text, 
parametro text[])

RETURNS SETOF refcursor AS
$BODY$
Declare
rc refcursor; /*doid_pers text; deuda double precision; pago double precision; dscto double precision; costas double precision; saldo double precision;*/
begin
    If $1='DNI' THEN
        OPEN rc FOR
        select      P.doid_pers as RazonSocial ,
                P.razo_soc as Infractor, 
                P.dire_pers as Domicilio, 
                U.ubicacion as Distrito, 
                I.nume_pape as Papeleta, 
                CU.codi_cuis as Infraccion, 
                I.fech_noti as Fecha, 
                E.desc_esta as Estado,
                sum(I.tota_pago + PG.valo_rein + PG.valo_cost) as Deuda,
                sum(PG.mont_pago) as Pago,
                sum(PG.des_pago) as Dsct,
                sum(PG.valo_cost) as Costas,
                (sum(I.tota_pago + PG.valo_rein + PG.valo_cost)-sum(PG.mont_pago+PG.des_pago+PG.valo_cost)) as Saldo
            From gf.persona as P 
            Inner Join gf.ubigeo as U On (P.ubigeo = U.ubigeo)
            Inner Join gf.gf_tb_cuenta as C On (P.doid_pers = C.doid_pers)
            Inner Join gf.gf_tb_infraccion_cnta as I on (C.codi_cnta=I.codi_cnta and C.anio_cnta=I.anio_cnta)
            Inner Join gf.gf_tb_infraccion_cnta_admi as A on (I.codi_inct=A.codi_inct and I.codi_cnta=A.codi_cnta and I.anio_cnta=A.anio_cnta)
            Inner Join gf.cuis as CU on (A.corr_cuis=CU.corr_cuis)
            Inner Join gf.gf_tb_pago as PG on (A.codi_inct=PG.codi_inct and A.codi_cnta=PG.codi_cnta and A.anio_cnta=PG.anio_cnta)  
            Inner Join gf.estado_pago as E on (E.codi_espa=I.codi_espa) 
            Where P.doid_pers=parametro[1]
            Group By P.doid_pers,P.razo_soc,P.dire_pers,U.ubicacion,I.nume_pape,CU.codi_cuis,I.fech_noti,E.desc_esta ;
            return next rc;
    END IF;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
}
    
asked by Yefferson Socla Urbano 27.03.2018 в 23:45
source

0 answers