From: | Marcos <mjs_ops(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | What is made a mistake with SP? |
Date: | 2006-01-23 08:27:14 |
Message-ID: | 1138004834.949.19.camel@servidor |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I need create SP that returns cursos so that I can work with them.
I have many SQLs used for search records in database, then I will make
SP to return the results.
The example that I'm trying is:
CREATE OR REPLACE FUNCTION fun_compras_calculado() RETURNS SETOF
tipo_compras_calculado AS '
DECLARE
linha_compras RECORD;
linha_calculada tipo_compras_calculado;
BEGIN
linha_calculada.acumulado := 0;
FOR linha_compras IN
SELECT id, qtd, produto, unitario FROM compras ORDER BY id
LOOP
linha_calculada.id := linha_compras.id;
linha_calculada.produto := linha_compras.produto;
linha_calculada.qtd := linha_compras.qtd;
linha_calculada.unitario := linha_compras.unitario;
linha_calculada.valor := linha_compras.qtd * linha_compras.unitario;
linha_calculada.acumulado := linha_calculada.acumulado + linha_calculada.valor;
RETURN NEXT linha_calculada;
END LOOP;
RETURN;
END;
' LANGUAGE 'plpgsql';
From | Date | Subject | |
---|---|---|---|
Next Message | surabhi.ahuja | 2006-01-23 08:34:26 | Re: logging connections |
Previous Message | Martijn van Oosterhout | 2006-01-23 08:26:27 | Re: Numbers |