Search Postgresql Archives

What is made a mistake with SP?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux