Saludos.
Tengo MySQL 5.7.22 y utilizo para acceder a ella Navicat la última versión y deseo crear esta función y sipre que lo intento hacer, ya sea manual o copiando este código me da errores y no lo hace, no se cómo hacerla, ¿me pueden ayudar?
CREATE FUNCTION `digitoVerificador`(rut INT UNSIGNED) RETURNS varchar(1)
BEGIN
DECLARE dv VARCHAR(1);
DECLARE Digito INT;
DECLARE Contador INT;
DECLARE Multiplo INT;
DECLARE Acumulador INT;
SET Contador = 2;
SET Acumulador = 0;
SET Multiplo = 0;
WHILE(rut!=0) DO
SET Multiplo = (rut%10) * Contador;
SET Acumulador = Acumulador + Multiplo;
SET rut = FLOOR(rut / 10);
SET Contador = Contador + 1;
if(Contador = 8) THEN
SET Contador = 2;
END IF;
END WHILE;
SET Digito = 11 - (Acumulador%11);
SET dv = LTRIM(RTRIM(CAST(Digito as CHAR(2))));
IF(Digito = 10) THEN
SET dv = 'K';
END IF;
IF(Digito = 11) THEN
SET dv = '0';
END IF;
RETURN dv;
END