30 lines
550 B
SQL
30 lines
550 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`validationCode`(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 ;
|