oracle 如何得到人民币的大写形式

 create or replace function getBigMoneyStr(money In number) return varchar2 is
  tmp_str   varchar2(20);
  money_str varchar2(20);
  val_j     varchar2(20);
  len_j     number;
  k         number;
  i         number;
  j         number;
  m         number;
  result    varchar2(40);
  type my_type is varray(20) of varchar2(4);
  num     constant my_type := my_type('1',
                                      '2',
                                      '3',
                                      '4',
                                      '5',
                                      '6',
                                      '7',
                                      '8',
                                      '9',
                                      '0');
  num_str constant my_type := my_type('壹',
                                      '贰',
                                      '叁',
                                      '肆',
                                      '伍',
                                      '陆',
                                      '柒',
                                      '捌',
                                      '玖',
                                      '零');
begin
  tmp_str := to_char(money * 100);
  len_j   := length(tmp_str);
  k       := 11 - len_j;
  result  := substr(tmp_str, 1, 1);
  m       := 2;
  for i in 1 .. len_j loop
    begin
      if k = 1 then
        money_str := '仟';
      elsif k = 2 then
        money_str := '佰';
      elsif k = 3 then
        money_str := '拾';
      elsif k = 4 then
        money_str := '万';
      elsif k = 5 then
        money_str := '仟';
      elsif k = 6 then
        money_str := '佰';
      elsif k = 7 then
        money_str := '拾';
      elsif k = 8 then
        money_str := '元';
      elsif k = 9 then
        money_str := '角';
      elsif k = 10 then
        money_str := '分';
      end if;
   
      k     := k + 1;
      m     := i + 1;
      val_j := nvl(substr(tmp_str, m, 1), '');
      if len_j = m + 5 and substr(result, length(result), 1) = '0' then
        result := substr(result, 0, length(result) - 1) || '万0';
      end if;
   
      if len_j = m + 1 and substr(result, length(result), 1) = '0' then
        result := substr(result, 0, length(result) - 1) || '元0';
      end if;
   
      if val_j = '0' and substr(result, length(result), 1) = '0' then
        goto TheEnd;
      end if;
   
      if substr(result, length(result), 1) != '0' then
        result := result || money_str;
      end if;
   
      result := result || val_j;
   
      <<TheEnd>>
      null;
    end;
  end loop;
  --除去最后的0
  for j in 1 .. 3 loop
    begin
      if substr(result, length(result), 1) = '0' then
        result := substr(result, 0, length(result) - 1);
      end if;
    end;
  end loop;
  for i in 1 .. 10 loop
    result := replace(result, num(i), num_str(i));
  end loop;

  return result;
end;
来自:http://jametong.itpub.net/category/5042/9386

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值