MySQL金额数字转为大写中文

database

MySQL版本:5.7.34-log

通过创建函数的方法,目前可以实现整数金额的转换,网上暂未找到MySQL版本的故自己参照其他数据库版本的改编了一下,仅供参考!!!

使用方法:select rmb(10000)

CREATE DEFINER = `root`@`%` FUNCTION `rmb_upper`(je int)

RETURNS varchar(200)

DETERMINISTIC

BEGIN

#Routine body goes here...

declare je_number varchar(200);

declare je_upper varchar(200);

declare je_part varchar(200);

declare i int;

set i=1;

set je_upper="";

while i<=length(je) do

set je_part= concat(

case substring(je, length(je)-i+1, 1)

when "0" then "零"

when "1" then "壹"

when "2" then "贰"

when "3" then "叁"

when "4" then "肆"

when "5" then "伍"

when "6" then "陆"

when "7" then "柒"

when "8" then "捌"

when "9" then "玖"

end

,

case i

when 1 then "元"

when 2 then "拾"

when 3 then "佰"

when 4 then "仟"

when 5 then "万"

when 6 then "拾"

when 7 then "佰"

when 8 then "仟"

when 9 then "亿"

end);

set je_upper=concat(je_part,je_upper);

set i=i+1;

end while;

set je_upper = REPLACE(je_upper,"零拾","零");

set je_upper = REPLACE(je_upper,"零佰","零");

set je_upper = REPLACE(je_upper,"零仟零佰零拾","零");

set je_upper = REPLACE(je_upper,"零仟","零");

set je_upper = REPLACE(je_upper,"零零零","零");

set je_upper = REPLACE(je_upper,"零零","零");

set je_upper = REPLACE(je_upper,"零角零分","");

set je_upper = REPLACE(je_upper,"零分","");

set je_upper = REPLACE(je_upper,"零角","零");

set je_upper = REPLACE(je_upper,"零亿零万零元","亿元");

set je_upper = REPLACE(je_upper,"亿零万零元","亿元");

set je_upper = REPLACE(je_upper,"零亿零万","亿");

set je_upper = REPLACE(je_upper,"零万零元","万元");

set je_upper = REPLACE(je_upper,"万零元","万元");

set je_upper = REPLACE(je_upper,"零亿","亿");

set je_upper = REPLACE(je_upper,"零万","万");

set je_upper = REPLACE(je_upper,"零元","元");

set je_upper = REPLACE(je_upper,"零零","零");

if left(je_upper,1)="元" then set je_upper = REPLACE(je_upper,"元","零元");

end if;

set je_upper=concat(je_upper,"整");

RETURN je_upper;

END;

参考文章:《sql 数字转人民币大写函数(两种方法)》

以上是 MySQL金额数字转为大写中文 的全部内容, 来源链接: utcz.com/z/536388.html

回到顶部