Function get_number_chinese (p_number Number)
Return Varchar2 Is
l_chinese Varchar2(80);
l_wei Varchar2(20);
l_need Varchar2(80);
flag number:=0;
Begin
select TRANSLATE(p_number,'0123456789','零壹贰叁肆伍陆柒捌玖')
Into l_chinese
from dual;
Select '元十百千万十百千亿十'
Into l_wei
From dual;
For cur In 1..length(p_number) Loop
If flag=8 Then l_need:=substr(l_need,2,20);End If;
If substr(l_chinese,length(l_chinese)+1-cur,1)<>'零' Then
If 6<=flag Then l_need:=substr(l_chinese ,length(l_chinese)-cur+1,1)||substr( l_wei,cur,1)||substr(l_need,2,40); FLAG:=0;
Else
l_need:=substr(l_chinese ,length(l_chinese)-cur+1,1)||substr( l_wei,cur,1)||l_need;
FLAG:=0;
End If;
Else
If MOD(CUR,4)=1 Then l_need:=substr( l_wei,cur,1)||l_need;FLAG:=5;
Else
If FLAG=0 Or FLAG=5 Then l_need:='零'||l_need;
FLAG:=flag+1;
Else FLAG:=flag+1;
End If;
End If;
End If;
End Loop;
Return (l_need);
End ;
Return Varchar2 Is
l_chinese Varchar2(80);
l_wei Varchar2(20);
l_need Varchar2(80);
flag number:=0;
Begin
select TRANSLATE(p_number,'0123456789','零壹贰叁肆伍陆柒捌玖')
Into l_chinese
from dual;
Select '元十百千万十百千亿十'
Into l_wei
From dual;
For cur In 1..length(p_number) Loop
If flag=8 Then l_need:=substr(l_need,2,20);End If;
If substr(l_chinese,length(l_chinese)+1-cur,1)<>'零' Then
If 6<=flag Then l_need:=substr(l_chinese ,length(l_chinese)-cur+1,1)||substr( l_wei,cur,1)||substr(l_need,2,40); FLAG:=0;
Else
l_need:=substr(l_chinese ,length(l_chinese)-cur+1,1)||substr( l_wei,cur,1)||l_need;
FLAG:=0;
End If;
Else
If MOD(CUR,4)=1 Then l_need:=substr( l_wei,cur,1)||l_need;FLAG:=5;
Else
If FLAG=0 Or FLAG=5 Then l_need:='零'||l_need;
FLAG:=flag+1;
Else FLAG:=flag+1;
End If;
End If;
End If;
End Loop;
Return (l_need);
End ;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/87010/viewspace-417493/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/87010/viewspace-417493/