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';


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Reply via email to