2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`validationCode`(vString VARCHAR(255))
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURNS int(11)
|
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
DECLARE vSeed DOUBLE DEFAULT 0;
|
|
|
|
DECLARE vCode INT;
|
|
|
|
DECLARE vLength INT;
|
|
|
|
DECLARE vChar INT;
|
|
|
|
|
|
|
|
SET vLength = length(vString);
|
|
|
|
|
|
|
|
WHILE vLength > 0 DO
|
|
|
|
|
|
|
|
SET vChar = MID(vString,vLength,1);
|
|
|
|
|
|
|
|
SET vSeed = vSeed + ASCII(vChar);
|
|
|
|
|
|
|
|
SET vLength = vLength - 1;
|
|
|
|
|
|
|
|
END WHILE;
|
|
|
|
|
|
|
|
SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000;
|
|
|
|
|
|
|
|
RETURN vCode;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|