CREATE DEFINER = ‘root‘@‘localhost‘
FUNCTION myhouse.change_to_num(cn_num varchar(255))
RETURNS int(11)
begin
declare i int default 1;
declare result int default 0;
declare str varchar(10);
declare num int;
declare temp int default 1;
while i <= char_length(cn_num) do
set str = substring(cn_num, i, 1);
set num = case str
when ‘零‘ then 0
when ‘壹‘ then 1
when ‘贰‘ then 2
when ‘叁‘ then 3
when ‘肆‘ then 4
when ‘伍‘ then 5
when ‘陆‘ then 6
when ‘柒‘ then 7
when ‘捌‘ then 8
when ‘玖‘ then 9
when ‘拾‘ then 10
when ‘佰‘ then 100
when ‘仟‘ then 1000
ELSE 0
end;
if num!=10 && num!=100 && num!=1000 then
set temp = num;
IF i=char_length(cn_num) THEN
SET result = result + temp;
END IF;
else
set result = result + (temp * num);
end if;
set i = i + 1;
end while;
return result;
end
原文:https://www.cnblogs.com/CodeBunny/p/13097514.html