视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
大写金额转换函数
2025-09-29 03:04:12 责编:小OO
文档
set serveroutput on;

CREATE or replace Function Disp_dxje(THe_fyhj In Number) return varchar2 Is

/**********************************************************************

* 名称:大写金额转换函数 *

* 功能:收费打使用此函数 *

************************************************************************/

temp varchar2(16):=null; --the_fyhj字符串

temp1 varchar2(2):=null; --the_fyhj各小写字符

temp2 varchar2(2):=null; --the_fyhj各大写字符

temp3 varchar2(6):=null; --the_fyhj各大写单位

temp4 varchar2(60):=Null; --the_fyhj大写金额串

i number(2):=1;

j number(2);

pp number(2); --整数位长度

len number(2); --实际位长度

ll Number:=round(THe_fyhj,2);

Begin

if The_fyhj <0 Then

ll:=The_fyhj*(-1);

End if;

temp:=ltrim(rtrim(to_char(ll)),'0');--转成字符串,并去左边多余的零

pp:=Instr(temp,'.');

if pp>0 then

temp:=ltrim(Temp,'0'); --有小数时去掉右边多余的零

end if;

len:=length(temp);

if len>16 then --费用超限

return '费用超限';

End if;

if pp>0 then --整数位长度

pp:=pp-1;

Else

pp:=len;

End if;

for i in 1..len loop

temp1:=substr(temp,i,1); --取大写数值

if temp1='1' then

temp2:='壹';

elsif temp1='2' then

temp2:='贰';

elsif temp1='3' then

temp2:='叁';

elsif temp1='4' then

temp2:='肆';

elsif temp1='5' then

temp2:='伍';

elsif temp1='6' then

temp2:='陆';

elsif temp1='7' then

temp2:='柒';

elsif temp1='8' then

temp2:='捌';

elsif temp1='9' then

temp2:='玖';

elsif temp1='0' then

temp2:='零';

else

temp2:=null;

end if;

j:=pp+1-i;

If j=13 then --取大写单位

temp3:='万'; --亿级

elsif j=12 then

temp3:='仟'; --亿级

elsif j=11 then

temp3:='佰'; --亿级

elsif j=10 then

temp3:='拾'; --亿级

elsif j=9 then

temp3:='亿';

elsif j=8 then

temp3:='仟'; --万级

elsif j=7 then

temp3:='佰'; --万级

elsif j=6 then

temp3:='拾'; --万级

elsif j=5 then

temp3:='万';

elsif j=4 then

temp3:='仟';

elsif j=3 then

temp3:='佰';

elsif j=2 then

temp3:='拾';

elsif j=1 then

temp3:='元';

elsif j=-1 then

temp3:='角';

elsif j=-2 then

temp3:='分';

else

temp3:=null;

End if;

If j<-2 Then

temp2:=null;

End If;

If temp2='零' and temp3 Not In('亿','万','元') then --取消无效的单位

temp3:=null;

End if;

temp4:=temp4||temp2||temp3;

temp4:=replace(Temp4,'零零','零'); --取消无效的零

end loop;

--取消无效的零

temp4:=replace(Temp4,'零万','万');

temp4:=replace(Temp4,'零亿','亿');

temp4:=replace(Temp4,'亿万','亿');

If ll!=0 then

temp4:=replace(temp4,'零元','元');

End if;

if the_fyhj>=0 then

if (ll*10-floor(ll*10))=0 then --整数费用

temp4:='币'||temp4||'整';

else --小数费用

temp4:='币'||temp4;

end if;

Else

if (ll*10-floor(ll*10))=0 then

temp4:='币负'||temp4||'整';

else

temp4:='币负'||temp4;

end if;

End if;

return temp4;

Exception

When Others Then

return sqlerrm;

End Disp_dxje;

declare

dxje varchar2(100);

begin

dxje:=disp_dxje(-132423423503.333);

dbms_output.put_line(dxje);

end;下载本文

显示全文
专题