编程:
关于人民币的转换:将一个阿拉伯数字转换成用中文汉字表示,如123转换成壹百贰十三
(注意:金额可能会达到百万,甚至亿)

解决方案 »

  1.   

    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;不要说你不会用JAVA调用...........
      

  2.   

    拜托不符合要求的不要拿出来忽悠人SQL code
      

  3.   

    package money;public class ChangeMoney2 { public static void main(String[] args) {
    float money = new Float(121.01);
    new ChangeMoney2().change(money);
    int i =0;
    System.out.println(i=i++);
    } public void change(float money) {
    if (0 >= money) {
    System.out.println("一分钱都没有!");
    } else {
    String moneyStr = Float.toString(money);
    StringBuffer buff = new StringBuffer();
    String moneyInt = moneyStr.substring(0, moneyStr.indexOf("."));// 整数部分
    String moneyPoit = moneyStr.substring(moneyStr.indexOf(".") + 1);// 小数部分
    System.out.println(moneyStr); int length = moneyInt.length();// 整数的位数
    int position = 0;// 整数部分标记位 while (position < length) { switch (length - position - 1) {
    case 0: {
    System.out.println("整数部分:" + moneyInt + " 小数部分:"
    + moneyPoit);
    position = add(buff, moneyInt, position);
    buff.append("圆");

    continue;
    } case 9:
    case 5:
    case 1: {
    position = add(buff, moneyInt, position);
    buff.append("拾");
    continue;
    } case 10:
    case 6:
    case 2: {
    position = add(buff, moneyInt, position);
    buff.append("百");
    continue;
    } case 7:
    case 3: {
    position = add(buff, moneyInt, position);
    buff.append("千");
    continue;
    } case 4: {
    position = add(buff, moneyInt, position);
    buff.append("万");
    continue;
    } case 8: {
    position = add(buff, moneyInt, position);
    buff.append("亿");
    continue;
    } }
    }

    if (!moneyPoit.equals("0")) {
    System.out.println("只精确到小数点1位!");
    add(buff, moneyPoit, 0);
    buff.append("角");
    }

    moneyStr = buff.toString();
    moneyStr = moneyStr.replaceAll("0", "零");
    moneyStr = moneyStr.replaceAll("1", "壹");
    moneyStr = moneyStr.replaceAll("2", "贰");
    moneyStr = moneyStr.replaceAll("3", "叁");
    moneyStr = moneyStr.replaceAll("4", "肆");
    moneyStr = moneyStr.replaceAll("5", "伍");
    moneyStr = moneyStr.replaceAll("6", "陆");
    moneyStr = moneyStr.replaceAll("7", "柒");
    moneyStr = moneyStr.replaceAll("8", "捌");
    moneyStr = moneyStr.replaceAll("9", "玖");
    System.out.println(moneyStr);
    }
    } public int add(StringBuffer buff, String str, int i) { buff.append(str.charAt(i));
    return ++i;
    }}
      

  4.   

    其实我感觉自己用java代码来实现,应该不是一个最优的方法,我觉得用正则来匹配是最好。
    但是也有一个问题,你并没有指定金额的上限,也许判断远远都不能满足