mysql数据库实现BKDR散列算法(java字符串采用该散列算法)
DELIMITER //
create function t(in_str VARCHAR(255))
returns int
begin
declare i int;
declare l int;
declare min_int int;
declare max_int int;
declare r int;
set i = 1;
set r = 0;
set min_int = -2147483648;
set max_int = 2147483647;
select CHAR_LENGTH(in_str) into l;
if l < 1
then return(0);
end if;
while i <= l do
set r = overflow(31 * r + ASCII(substring(in_str, i, 1)));
set i=i+1;
end while;
return(r);
end
//
DELIMITER ;
overflow()参考<数据库数值类型溢出仿java处理方式>数据库数值类型溢出仿java处理方式>