From: | Felipe Araoz Ramos <faraoz(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-foro <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Actualizar registros en una tabla |
Date: | 2014-07-21 17:29:01 |
Message-ID: | CAM6fARxPiF=+x7tdX9w2JxDUuPWX5Gsc-8XErWnMueHMkZfmCw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Amigos
Estoy creando una funcion, para rrecorrer secuencialmente una tabla, de
principio a fin, actualizando el campo de stock en cada registro,
reinicializando la variable a cero cuando encuentra un nuevo producto y
continuar hasta terminar con el ultimo registro de la tabla. No me muestra
error, pero tampoco me esta actualizando el campo de la tabla. que podria
estar mal?. Espero vuestra ayuda.
CREATE Or REPLACE FUNCTION SALDOSTOCK()
RETURNS INTEGER
AS $$
DECLARE
codi character(12);
stk numeric (20,5);
fila_item infkrdx%ROWTYPE;
BEGIN
stk := 0;
for fila_item in SELECT * FROM INFKRDX LOOP
codi=fila_item.codiprod;
/*Acumulo el stock en variable stk */
stk := case when fila_item.cod_trans='I' then stk+fila_item.cantidad
else stk-fila_item.cantidad end;
UPDATE INFKRDX SET ST_FISICO=stk where n_operac=fila_item.n_operac;
if fila_item.codiprod<>INFKRDX.codi then stk := 0;
end if;
end loop;
end;
$$
language 'plpgsql'
Gracias
*Felipe Araoz Ramos*
RPM #941990605 / 941990605
RPC 992760385
NXT 822*9500 / 998229500
From | Date | Subject | |
---|---|---|---|
Next Message | Carlos Bazán | 2014-07-21 19:04:48 | Re: Actualizar registros en una tabla |
Previous Message | Alvaro Herrera | 2014-07-21 16:18:36 | Re: ERROR: invalid memory alloc request size |