DELIMITER $$
CREATE
FUNCTION `jtorder`.`F_GET_HASH_VALUE`(str VARCHAR(500))
RETURNS BIGINT
BEGIN
/*
* @desc:获取字符的HashValue
str:字符
* @author:shiyj
eg:str=abc123
*/
DECLARE result BIGINT;
SET @pos = 1;
SET @hashValue = 0;
-- 616263313233
SET @szHex = HEX(str);
-- 12
SET @size = LENGTH(@szHex);
WHILE @pos<@size+1 DO
-- 61
SET @cCh = SUBSTRING(@szHex,@pos,2);
-- a的ASCII=97
SET @nCh = CAST(ASCII(UNHEX(@cCh)) AS UNSIGNED);
-- 97+98+99+49+50+51
SET @hashValue = @hashValue + @nCh;
SET @pos = @pos + 2;
END WHILE;
SET result = @hashValue;
RETURN result;
END$$
DELIMITER ;
时间: 2024-10-29 19:07:38