金额大小写转换(4)

create   or   replace   function  l2u  --  小写金额转换成大写
(n_lowermoney  in   number return   varchar2   as
    v_lowerstr  
varchar2 ( 200 );  --  小写金额
    v_upperpart  varchar2 ( 200 );
    v_upperstr  
varchar2 ( 200 );  --  大写金额
begin
    v_lowerstr :
=   ltrim ( rtrim (to_char( round (n_lowermoney,  2 ),
                                      
' 9999999999999.99 ' )));
    
if  substr(v_lowerstr,  1 1 =   ' # '   then
        
return   ' 转换金额超过计算范围(计算范围为:计算范围为: 0 - 9,999,999,999,999.99) ' ;
    
end   if ;
    
for  i  in   1  .. length(v_lowerstr)
    loop
        
select  decode(substr(v_lowerstr, length(v_lowerstr)  -  i  +   1 1 ),
                      
' . ' ,
                      
' ' ,
                      
' 0 ' ,
                      
' ' ,
                      
' 1 ' ,
                      
' ' ,
                      
' 2 ' ,
                      
' ' ,
                      
' 3 ' ,
                      
' ' ,
                      
' 4 ' ,
                      
' ' ,
                      
' 5 ' ,
                      
' ' ,
                      
' 6 ' ,
                      
' ' ,
                      
' 7 ' ,
                      
' ' ,
                      
' 8 ' ,
                      
' ' ,
                      
' 9 ' ,
                      
' ' ||  decode(i,
                                     
1 ,
                                     
' ' ,
                                     
2 ,
                                     
' ' ,
                                     
3 ,
                                     
null ,
                                     
4 ,
                                     
null ,
                                     
5 ,
                                     
' ' ,
                                     
6 ,
                                     
' ' ,
                                     
7 ,
                                     
' ' ,
                                     
8 ,
                                     
' ' ,
                                     
9 ,
                                     
' ' ,
                                     
10 ,
                                     
' ' ,
                                     
11 ,
                                     
' ' ,
                                     
12 ,
                                     
' 亿 ' ,
                                     
13 ,
                                     
' ' ,
                                     
14 ,
                                     
' ' ,
                                     
15 ,
                                     
' ' ,
                                     
16 ,
                                     
' ' ,
                                     
null )
          
into  v_upperpart
          
from  dual;
        v_upperstr :
=  v_upperpart  ||  v_upperstr;
    
end  loop;

    v_upperstr :
=   replace (v_upperstr,  ' 零拾 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零佰 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零仟 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零零零 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零零 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零角零分 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零分 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零角 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零亿零万零元 ' ' 亿元 ' );
    v_upperstr :
=   replace (v_upperstr,  ' 亿零万零元 ' ' 亿元 ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零亿零万 ' ' 亿 ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零万零元 ' ' 万元 ' );
    v_upperstr :
=   replace (v_upperstr,  ' 万零元 ' ' 万元 ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零亿 ' ' 亿 ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零万 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零元 ' ' ' );
    v_upperstr :
=   replace (v_upperstr,  ' 零零 ' ' ' );

    
--  对壹元以下的金额的处理
    v_upperstr : =   ltrim ( ltrim ( ltrim ( ltrim (v_upperstr,  ' ' ),  ' ' ),  ' ' ),
                        
' ' );
    
if  substr(v_upperstr,  1 1 =   ' '   then
        v_upperstr :
=   ' 零元整 ' ;
    
end   if ;

    
return  v_upperstr;
exception
    
when  others  then
        
return   ' 发生错误:  '   ||  sqlcode  ||   ' -- '   ||  sqlerrm;
end  l2u;


转载于:https://www.cnblogs.com/benio/archive/2010/12/31/1923254.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值