O.T.: ¿Alguien me puede ayudar para crear esta funcion en MySQL?

38 views
Skip to first unread message

Alejandro Garcia G.

unread,
Jun 18, 2018, 4:21:56 PM6/18/18
to Comunidad de Visual Foxpro en Español
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
Reply all
Reply to author
Forward
0 new messages