ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 人民大写转换

人民大写转换

原创 Linux操作系统 作者:yobyin 时间:2009-06-05 14:38:37 0 删除 编辑

create or replace function F_upper_money(p_num in number default null)
return nvarchar2 is

Result nvarchar2(100);
num_round nvarchar2(100) :=to_char(abs(round(p_num,2)));
num_left nvarchar2(100);
num_right nvarchar2(2);
str1 nchar(10) :='零壹贰叁肆伍陆柒捌玖';
str2 nchar(16) :='元拾佰仟万拾佰仟亿拾佰仟万拾佰仟';
num_pre number(1):=1;
num_current number(1);
num_count number:=0;

begin
if p_num is null then return null;end if;

select to_char(
nvl(substr(to_char(num_round),1,
decode(instr(to_char(num_round),'.'),0,
length(num_round),instr(to_char(num_round),'.')-1)),
0)) into num_left from dual;
select substr(to_char(num_round),
decode(instr(to_char(num_round),'.'),0,
length(num_round)+1,instr(to_char(num_round),'.')+1),2)
into num_right from dual;

if length(num_left)>16 then return '**********'; end if;

if length(num_right)=2 then
if to_number(substr(num_right,1,1))=0 then
result:='零'||substr(str1,to_number(substr(num_right,2,1))+1,1)||'分';
else
result:=substr(str1,to_number(substr(num_right,1,1))+1,1)||'角'||
substr(str1,to_number(substr(num_right,2,1))+1,1)||'分';
end if;
elsif length(num_right)=1 then
result:=substr(str1,to_number(substr(num_right,1,1))+1,1)||'角整';
else
result :='整';
end if;

for i in reverse 1..length(num_left) loop
num_count:=num_count+1;
num_current:=to_number(substr(num_left,i,1));
if num_current>0 then
result:=substr(str1,num_current+1,1)||substr(str2,num_count,1)||result;
else
if mod(num_count-1,4)=0 then
result:=substr(str2,num_count,1)||result;
num_pre:=0;
end if;
if num_pre>0 or length(num_left)=1 then
result:=substr(str1,num_current+1,1)||result;
end if;
end if;
num_pre:=num_current;
end loop;

if p_num<0 then
result:='负'||result;
end if;

return Result;

exception
when others then
raise_application_error(-20001,'数字转换大写出现错误!'||sqlerrm);
end ;


 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8013558/viewspace-605248/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-03-31

  • 博文量
    45
  • 访问量
    106092