您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页银行金额小写转大写functionORACLE

银行金额小写转大写functionORACLE

来源:保捱科技网


平台:oracle 项目:银行支票打印功能实现小写转大写 代码出处:原创 之前网上找过相关类似的功能,但是经过测试还是会有部分漏洞,现在这些漏洞基本上解决,但难免会有遗漏希望指出。 无 create or replaceFunction Money2Chinese(moneyValues In Number) Re

平台:oracle
项目:银行支票打印功能实现小写转大写
代码出处:原创
之前网上找过相关类似的功能,但是经过测试还是会有部分漏洞,现在这些漏洞基本上解决,但难免会有遗漏 希望指出。 <无> $velocityCount-->
create or replace
Function Money2Chinese(moneyValues In Number) Return Varchar2 Is
 --moneyValue := Round(to_number(moneyValue))*100
 Str1 NCHAR(10) := '零壹贰叁肆伍陆柒捌玖';
 Str2 NCHAR(15) := '萬仟佰拾亿仟佰拾萬仟佰拾元角分';
 Str3 Number(10);
 moneyValue Varchar2(100) := trim(to_char(moneyValues)*100); --保留小数并去掉小数点后的值
 chineseValue Varchar2(600);
 lens Number := trim(length(moneyValue));
 nZero Number := 0;
 cha1 NCHAR(10);
 cha2 NCHAR(10);
Begin 
 --判断为空时
 If lens Is Null Then 
 Return Null;
 End If;
 --判断位数超长时 超过15位不进行处理 
 If lens >15 Then
 Return '超出银行支票取值范围';
 End If;
 If moneyValue = 0 Then
 Return '零元整';
 End If;
 --以上条件测试之后可以运行
 
 
 --下面条件选项待测
 Str2 := substr(Str2,(length(Str2)-lens)+1, lens);
 For i In 1..lens Loop
 Str3 := substr(trim(moneyValue),i,1);
 --循环遍历数值
 If i <> lens-2 and i <> lens-6 and i <> lens-10 and i <>lens-14 --不是万亿,亿,万,元位等关键位
 Then
 IF Str3=0 Then
 cha1 := '';
 cha2 := '';
 nZero := nZero +1;
 --第一个判断
 else
 IF Str3 <> 0 and nZero <> 0 Then
 cha1 := '零'||substr(Str1 , Str3+1 , 1);
 cha2 := substr(Str2 , i ,1 );
 nZero := 0;
 --第二个判断
 Else
 cha1 := substr(Str1 , (Str3+1) ,1);
 cha2 := substr(Str2 , i ,1);
 end if;
 End If;
 --是万亿,亿,万,元位等关键位
 Else
 IF Str3 <> 0 and nZero <> 0 Then
 cha1 := '零'||substr(Str1 , Str3+1 ,1);
 cha2 := substr(Str2 , i , 1);
 nZero := 0 ;
 Else
 If Str3 <> 0 and nZero = 0 Then
 cha1 := substr(Str1 , Str3+1 ,1);
 cha2 := substr(Str2 , i , 1);
 nZero := 0 ;
 Else
 If Str3 = 0 and nZero >= 3 Then
 cha1 := '';
 cha2 := '';
 nZero := nZero + 1;
 Else
 cha1 := '';
 cha2 := substr(Str2 , i ,1);
 nZero := nZero + 1;
 End If;
 End If;
 If i=(lens-10) or i = (lens - 2) Then
 cha2 := substr(Str2 , i ,1);
 End If;
 End If; 
 End IF;
 chineseValue := chineseValue||trim(cha1)||trim(cha2);
 End Loop;
 --结束循环
 If Str3 = 0 Then 
 chineseValue := chineseValue||'整';
 End If;
 Return chineseValue;
End Money2Chinese;

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务