Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/01/2013, 17:12
morhy_fernandez
 
Fecha de Ingreso: enero-2013
Mensajes: 6
Antigüedad: 11 años, 4 meses
Puntos: 0
Respuesta: error al tratar de insertar datos en una función de postgres

gracias por la ayuda.
He seguido tu consejo y cambie la tabla det_prestamos, por otra que contiene la llave primaria aparte y no relacionada directamente con la llave principal de la tabla prestmaos.- Mi necesidad es que me muestre en la tabla prestamos_pendientes, la cantidad de cuotas, con sus respectivos interese, amortizaciones y cuotas una por una, es decir si tiene 6 cuotas, visualice las 6 cuotas en la tabla, he modificado mi funcion, pero como resultado me arroja espacios en blanco, aalguna idea de como solucionar el problema.
desde ya gracia por la colaboración

create table prestamos_pendientes
(cod_presPend int not null, check(cod_presPend>0),
cod_pres int not null,
nro_cuo int not null, check(nro_cuo>=6 and nro_cuo<=30),
interes int not null, check(interes>0),
amortizacion int not null, check(amortizacion>0),
cuota int not null, check(cuota>=0),
fecha_venc date,
estado varchar(20),
primary key(cod_pres),
foreign key(cod_pres) references prestamos(cod_pres));

create or replace function sist_frances(a_codPres int,a_interes float,a_cant int,a_valor int)
returns void as $$
declare
v_ncuotas int:=0;
v_acumulado int:=0;
v_pendiente int:=a_valor;
v_amortAcum int:=0;
ou_interes int;
amort int;
x float:=a_interes;
y int:=a_cant;
c float;
c1 float;
i float;
maximo int;
codigo int;

begin
maximo=(select max(cod_presPend) from prestamos_pendientes)::integer;
if(maximo is null) then
maximo=0;
else
maximo=maximo+1;
codigo=maximo;

i:=x/100;
c:=((1+i)^y*i)/((1+i)^y-1);
c1=round(v_pendiente*c);

while(v_ncuotas< a_cant) loop
v_ncuotas=v_ncuotas+1;
ou_interes=round(v_pendiente*i);
v_acumulado=round(v_acumulado+ou_interes);
amort=round(c1-v_pendiente*i);
v_amortAcum=round(v_amortAcum+amort);
v_pendiente=round(v_pendiente-amort);
insert into prestamos_pendientes(cod_presPend,cod_pres,nro_cuo ,interes,amortizacion,cuota,fecha_venc,estado) values(codigo,a_codPres,v_ncuotas,ou_interes,amort ,c1,'1995-01-01','pendiente');
end loop;
end if;
end;
$$ LANGUAGE plpgsql

y el resultado da los campos en blanco