对于数字大小写的转换,也是有一定中国特色的东西。但是在账务报表中,我们还是需要有这样的功能的。今天写了一个将数字金额转化为大写的函数。
创新互联公司自2013年起,先为宁县等服务建站,宁县等地企业,进行企业商务咨询服务。为宁县企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
功能:将任意长度的数字金额转化为大写。***位为圆或角时,后面加“整”;为“分”时不加“整”。
说明:小数点后保留两位。超过两位的部分被截断。
代码:
- PL/SQL 代码
- Create Or Replace Function Money2Chinese(Money In Number) Return Varchar2 Is
- strYuan Varchar2(150);
- strYuanFen Varchar2(152);
- numLenYuan Number;
- numLenYuanFen Number;
- strRstYuan Varchar2(600);
- strRstFen Varchar2(200);
- strRst Varchar2(800);
- Type typeTabMapping Is Table Of Varchar2(2) Index By Binary_Integer;
- tabNumMapping typeTabMapping;
- tabUnitMapping typeTabMapping;
- numUnitIndex Number;
- i Number;
- j Number;
- charCurrentNum Char(1);
- Begin
- If Money Is Null Then
- Return Null;
- End If;
- strYuan := TO_CHAR(FLOOR(Money));
- If strYuan = '0' Then
- numLenYuan := 0;
- strYuanFen := lpad(TO_CHAR(FLOOR(Money * 100)), 2, '0');
- Else
- numLenYuan := length(strYuan);
- strYuanFen := TO_CHAR(FLOOR(Money * 100));
- End If;
- If strYuanFen = '0' Then
- numLenYuanFen := 0;
- Else
- numLenYuanFen := length(strYuanFen);
- End If;
- If numLenYuan = 0 Or numLenYuanFen = 0 Then
- strRst := '零圆整';
- Return strRst;
- End If;
- tabNumMapping(0) := '零';
- tabNumMapping(1) := '壹';
- tabNumMapping(2) := '贰';
- tabNumMapping(3) := '叁';
- tabNumMapping(4) := '肆';
- tabNumMapping(5) := '伍';
- tabNumMapping(6) := '陆';
- tabNumMapping(7) := '柒';
- tabNumMapping(8) := '捌';
- tabNumMapping(9) := '玖';
- tabUnitMapping(-2) := '分';
- tabUnitMapping(-1) := '角';
- tabUnitMapping(1) := '';
- tabUnitMapping(2) := '拾';
- tabUnitMapping(3) := '佰';
- tabUnitMapping(4) := '仟';
- tabUnitMapping(5) := '万';
- tabUnitMapping(6) := '拾';
- tabUnitMapping(7) := '佰';
- tabUnitMapping(8) := '仟';
- tabUnitMapping(9) := '亿';
- For i In 1 .. numLenYuan Loop
- j := numLenYuan - i + 1;
- numUnitIndex := Mod(i, 8);
- If numUnitIndex = 0 Then
- numUnitIndex := 8;
- End If;
- If numUnitIndex = 1 And i > 1 Then
- strRstYuan := tabUnitMapping(9) || strRstYuan;
- End If;
- charCurrentNum := substr(strYuan, j, 1);
- If charCurrentNum <> 0 Then
- strRstYuan := tabNumMapping(charCurrentNum) ||
- tabUnitMapping(numUnitIndex) || strRstYuan;
- Else
- If (i = 1 Or i = 5) Then
- If substr(strYuan, j - 3, 4) <> '0000' Then
- strRstYuan := tabUnitMapping(numUnitIndex) || strRstYuan;
- End If;
- Else
- If substr(strYuan, j + 1, 1) <> '0' Then
- strRstYuan := tabNumMapping(charCurrentNum) || strRstYuan;
- End If;
- End If;
- End If;
- End Loop;
- For i In -2 .. -1 Loop
- j := numLenYuan - i;
- charCurrentNum := substr(strYuanFen, j, 1);
- If charCurrentNum <> '0' Then
- strRstFen := tabNumMapping(charCurrentNum) || tabUnitMapping(i) ||
- strRstFen;
- End If;
- End Loop;
- If strRstYuan Is Not Null Then
- strRstYuan := strRstYuan || '圆';
- End If;
- If strRstFen Is Null Then
- strRstYuan := strRstYuan || '整';
- Elsif length(strRstFen) = 2 And substr(strRstFen, 2) = '角' Then
- strRstFen := strRstFen || '整';
- End If;
- strRst := strRstYuan || strRstFen;
- --strRst := Replace(strRst, '亿零', '亿');
- --strRst := Replace(strRst, '万零', '万');
- Return strRst;
- End Money2Chinese;
测试SQL如下:
- Select Money2Chinese(0932402934024.213) From dual;
结果:
玖仟叁佰贰拾肆亿零贰佰玖拾叁万肆仟零贰拾肆圆贰角整
测试通过
当前名称:详解Oracle中数字与大写交换
新闻来源:http://www.mswzjz.cn/qtweb/news13/250463.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能