MySQL Forums
Forum List  »  Spanish

Problema con procedimiento
Posted by: José Vicente Zahonero
Date: July 06, 2016 09:45AM

Hola, tengo el siguiente procedimiento:
CREATE DEFINER=`root`@`localhost` PROCEDURE `calculo_fecha`()
BEGIN
DECLARE contador int default 1;
declare dif_max int default 0;
declare tempo_max date;
declare tempo_min date;
declare resta int;
declare total_reg int;
declare hecho int default 0;
declare puntero CURSOR for SELECT fecha from datos order by salida_num asc;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET hecho = 1;

open puntero;
SELECT found rows INTO total_reg;
miloop:LOOP

fetch puntero into tempo_max, tempo_min;
if hecho = 1 then
leave miloop;
end if;
if contador != 0 then
set tempo_min = (select fecha from datos where salida_num = contador);
set tempo_max = (select fecha from datos where salida_num = contador + 1);
set resta = tempo_max - tempo_min;
if resta > dif_max THEN
set dif_max = resta;
else set contador = contador + 1;
end if;
end if;
end loop;
close puntero;
select dif_max;
END
Se supone que lo que hace es recorrer toda la tabla 'datos' en busca de la mayor diferencia de días entre dos entradas consecutivas, el problema es que me muestra el error:
#1054 - Unknown column 'found' in 'field list'
¿Podéis ayudarme con el error?. Gracias.

Options: ReplyQuote


Subject
Views
Written By
Posted
Problema con procedimiento
1015
July 06, 2016 09:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.