salix/db/routines/vn/functions/validationCode_beta.sql

30 lines
553 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`validationCode_beta`(vString VARCHAR(255))
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 ;