mysql转换大写_数字转大写金额的函数

mysql转换大写_数字转大写金额的函数MySQL版本:5.7.34-log *通过创建函数的方法,目前可以实现整数金额的转换,网上暂未找到MySQL版本的故自己参照其他数据库版本的改编了一下,*仅供参考!!! 使用方法:select rm

MySQL金额数字转为大写中文

MySQL版本:5.7.34-log
通过创建函数的方法,目前可以实现整数金额的转换,网上暂未找到MySQL版本的故自己参照其他数据库版本的改编了一下,仅供参考!!!
使用方法:select rmb(10000)
mysql转换大写_数字转大写金额的函数

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 数字转人民币大写函数(两种方法)》

原文地址:https://www.cnblogs.com/qixinghaitang/archive/2022/03/31/16082056.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/5398.html

(0)
上一篇 2023-05-11
下一篇 2023-05-11

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注