9 Funciones
Objetivo
$$;
Paso 2
materiales LOOP
reg.nombrematerial
||
END LOOP;
return result;
end;
LANGUAGE plpgsql
AS $$
declare
nombre_edificaciones char ;
begin
Paso 4
p_NroNotaE
begin
select
materiales.nombrematerial,
materiales.cantidadenmano, materiales.unidaddemedida
into resultado from detalles_de_entrada
materiales
where detalles_de_entrada.idmaterial=
materiales.idmaterial
and
detalles_de_entrada.nroordencompra=pnroorden
and
detalles_de_entrada.nronotaentrega=pnronota;
end;
return resultado;
$_$;
Paso 5
return precio;
$$;
Paso 6
end;
end loop;
return resultado;
end;
$$;
Paso 8
update materiales
set ultimoprecio=(select detalles_de_entrada
.preciou from detalles_de_entrada
where detalles_de_entrada
.idfamilia=familia and detalles_de_entrada
.idgrupo='grupo'
and detalles_de_entrada
.idmaterial=material)
where materiales.idfamilia=familia and
materiales.idmaterial=material
and materiales.idgrupo=grupo;
if FOUND then
precio:=precio || 'actualizado correctamente';
else
precio:=precio || 'NO actualizo
correctamente';
end if;
return precio;
end;
$_$;
Paso 9
end;
declare
cr_materiales refcursor;
m_IdFamilia
m_IdGrupo
m_IdMaterial
begin
open cr_materiales for select
IdFamilia,IdGrupo,IdMaterial
from materiales order by IdFamilia,IdGrupo,IdMaterial;
loop
fetch next from cr_materiales into m_IdFamilia,
m_IdGrupo, m_IdMaterial;
exit when not found;
update
materiales set cantidadenmano = (select
ex.existencia from vw_existencias ex
where ex.idfamilia=m_IdFamilia and
ex.idgrupo=m_IdGrupo and ex.idmaterial=m_IdMaterial)
where idfamilia=m_IdFamilia and dgrupo=m_IdGrupo and
idmaterial=m_IdMaterial;
end loop;
close cr_materiales;
end;
$BODY$
LANGUAGE 'plpgsql'