My SQL Hash Coding algorithm for Chinese characters and letters

Source: Internet
Author: User

DELIMITER $$

CREATE

FUNCTION ' Jtorder '. ' F_get_hash_value ' (str VARCHAR (500))
RETURNS BIGINT

BEGIN
/*
* @desc: Get hashvalue of characters
STR: Characters
* @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);
--The ascii=97 of a
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;

My SQL Hash Coding algorithm for Chinese characters and letters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.