Re: Function doesn't work properly - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Function doesn't work properly
Date
Msg-id F4CC9C9D-7CE1-47D5-88CD-ADB3B2702F8A@solfertje.student.utwente.nl
Whole thread Raw
In response to Function doesn't work properly  (Ing. Eris J. Gómez <eris_jose@hotmail.com>)
List pgsql-general
On 14 Aug 2009, at 18:42, Ing. Eris J. Gómez wrote:

> Hi all.
>
> I wrote a function and it does not work properly. What am I doing
> wrong?
> *- Here is the script ..
>
> ---
> CREATE OR REPLACE FUNCTION "public"."cxp_balfactura" (x_codcia char,
> x_suplidor char, x_factura char, x_monto numeric, x_moneda integer)
> RETURNS numeric AS
> $body$
> DECLARE
>        cursor1  record;
>        debitos  numeric(14,2);
>        creditos numeric(14,2);
>        balance  numeric (14,2);
> BEGIN
>        balance := x_monto;
>
> --It doesn't execute this lines, why?

What makes you think that?

>
>        for cursor1 in select
> cxp_mov_item.tipo_transaccion,sum(item_monto+item_descuento) AS monto
>                from  cxp_mov_item,cxp_mov_head
>                where cxp_mov_item.cia_codigo = cxp_mov_head.cia_codigo
>                and   cxp_mov_item.mov_codigo = cxp_mov_head.mov_codigo
>                and   cxp_mov_item.fact_codigo = x_factura
>                and   cxp_mov_head.cia_codigo = x_codcia
>                and   cxp_mov_head.supl_codigo = x_suplidor
>                and   cxp_mov_head.id_moneda = x_moneda
>                and   cxp_mov_head.mov_estado <> '*'
>                GROUP by cxp_mov_item.tipo_transaccion

Does this query return any rows?

>       loop

You can raise a few notices in the loop body to see what's going on.
The value of tipo_transaccion is probably interesting.

>           if cursor1.tipo_transaccion = 'ND' then
>               debitos := debitos + cursor1.monto;
>           end if;
>
>           if cursor1.tipo_transaccion = 'CK' then
>               creditos := creditos + cursor1.monto;
>           end if;
>
>           if cursor1.tipo_transaccion = 'NC' then
>               creditos := creditos + cursor1.monto;
>           end if;
>       end loop;


Alban Hertroys

--
Screwing up is the correct approach to attaching something to the
ceiling.


!DSPAM:737,4a859c8010135542721450!



pgsql-general by date:

Previous
From: John R Pierce
Date:
Subject: Re: Proxy for postgres
Next
From: Martin Spinassi
Date:
Subject: Re: Proxy for postgres