在MSSQL中将数字转换成中文
具体代码如下:
CREATE FUNCTION [dbo].[fn_NumberToChinese] (@number INT) RETURNS VARCHAR(20) AS BEGIN DECLARE @res VARCHAR(20); DECLARE @str VARCHAR(10); DECLARE @char CHAR(1); SET @res = ‘‘; SET @str = CAST(@number AS VARCHAR); SET @char = SUBSTRING(@str, 1, 1); SELECT @res = ( CASE ( CAST(@char AS INT) ) 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 ‘九‘ ELSE ‘零‘ END ); IF ( LEN(@str) > 1 ) BEGIN SELECT @res = @res + ( CASE LEN(@str) WHEN 2 THEN ‘十‘ WHEN 3 THEN ‘百‘ WHEN 4 THEN ‘千‘ WHEN 5 THEN ‘万‘ WHEN 6 THEN ‘十‘ WHEN 7 THEN ‘百‘ ELSE ‘‘ END ); SET @res = @res + dbo.fn_NumberToChinese(CAST(SUBSTRING(@str, 2, LEN(@str) - 1) AS INT)); END; RETURN @res; END;
使用:
SELECT dbo.fn_NumberToChinese(‘21‘)
结果:
二十一
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。