I have to take out a stored procedure, to simplify fractions (divide by the same numerator and denominator number). However, when I run the script it stays running for a while and the MySQL connection is cut off.
My code is as follows:
delimiter //
create procedure simpfrac(IN denom int, IN numerad int)
begin
declare contador int;
set contador = 0;
-- Creamos un bucle en el cual usamos un contador para ir simplificando las fracciones
incremento: loop
set contador = contador+1;
if (denom % contador = 0) and (contador < denom) and (numerad % contador = 0) and (contador < numerad)
then
begin
set denom = denom / contador;
set numerad = numerad / contador;
end;
else if (numerad = denom)
then
begin
select 'El resultado es 1, no hace falta simplificar';
leave incremento;
end;
else if (denom < numerad) and (contador = denom)
then
leave incremento;
else if (denom > numerad) and (contador = numerad)
then
leave incremento;
end if;
end if;
end if;
end if;
end loop incremento;
end;//
delimiter ;