mysql中:中文转阿拉伯数字:如:三百转300

CREATE DEFINER="root"@"%" FUNCTION "China_NUM"(cn_num varchar(50)) RETURNS int(8)
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

测试: 

结果:

 备注:转载前记得给博主点赞呀~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值