• 将1亿以下阿拉伯数字转换为大写汉字


    declare
        cccc varchar2(30);
      nnnn number;
      n1 number;
      n2 number;
      n0 number;  --记录数字连续为0的个数,多个连续0转化为大写
                  --只写一个“零”
      i1 number;
    begin  
        --数字小写转大写
        nnnn:=:block2.item1;          --获取阿拉伯数字(:block2.item1为输入阿拉伯数字的域)
      if nnnn is NULL then
          nnnn:=0;
      end if;
      
     if nnnn<(10**8) then  --只转化小于1千万的数
        n1:=nnnn; 
      
      if nnnn<10000 then   --数字小于1万
        n0:=0;
          for i in reverse 1..4 loop  --从大到小循环
              n2:=floor(n1/(10**(i-1))); --求整数
            n1:=mod(n1,10**(i-1)); --求余数

          case n2
            when 0 then
              if (cccc IS NOT NULL) and (n0=0) and (n1!=0) then --当有第一个0且后面不全是0时,才写“零”
                    cccc:=cccc||'零';
              end if;
              n0:=n0+1;   
            
            when 1 then cccc:=cccc||'壹';n0:=0;
            when 2 then cccc:=cccc||'贰';n0:=0;
            when 3 then cccc:=cccc||'叁';n0:=0;
            when 4 then cccc:=cccc||'肆';n0:=0;
            when 5 then cccc:=cccc||'伍';n0:=0;
            when 6 then cccc:=cccc||'陆';n0:=0;
            when 7 then cccc:=cccc||'柒';n0:=0;
            when 8 then cccc:=cccc||'捌';n0:=0;
            when 9 then cccc:=cccc||'玖';n0:=0;
           end case;
          

           --2,为每一位数字加权
           if n2!=0 then   --取得的数字不为0才能加权
            case i
             when 1 then null;
             when 2 then cccc:=cccc||'拾';
             when 3 then cccc:=cccc||'百';
             when 4 then cccc:=cccc||'千';
             --when 5 then cccc:=cccc||'万';
            end case;       
           end if;

     end loop;
     
     
     ----大于1万
    else
        ---先转化万位以上的4位
        n1:=floor(nnnn/(10**4));    
        n0:=0;
          for i in reverse 1..4 loop  --从大到小循环
              n2:=floor(n1/(10**(i-1))); --求整数
            n1:=mod(n1,10**(i-1)); --求余数

          case n2
            when 0 then
              if (cccc IS NOT NULL) and (n0=0) and (n1!=0) then --当有第一个0且后面不全是0时,才写“零”
                    cccc:=cccc||'零';
              end if;
              n0:=n0+1;   
            
            when 1 then cccc:=cccc||'壹';n0:=0;
            when 2 then cccc:=cccc||'贰';n0:=0;
            when 3 then cccc:=cccc||'叁';n0:=0;
            when 4 then cccc:=cccc||'肆';n0:=0;
            when 5 then cccc:=cccc||'伍';n0:=0;
            when 6 then cccc:=cccc||'陆';n0:=0;
            when 7 then cccc:=cccc||'柒';n0:=0;
            when 8 then cccc:=cccc||'捌';n0:=0;
            when 9 then cccc:=cccc||'玖';n0:=0;
           end case;
          

           --2,为每一位数字加权
           if n2!=0 then   --取得的数字不为0才能加权
            case i
             when 1 then null;
             when 2 then cccc:=cccc||'拾';
             when 3 then cccc:=cccc||'百';
             when 4 then cccc:=cccc||'千';
             when 5 then cccc:=cccc||'万';
            end case;       
           end if;

        end loop;
        cccc:=cccc||'万';

          --以万位为界取低5位
          n1:=mod(nnnn,10000);  
       -- if n1<10000 then    --万位为0,则加'零'
       --     cccc:=cccc||'零';
        --end if;
        
        n0:=0;
          for i in reverse 1..4 loop  --从大到小循环
              n2:=floor(n1/(10**(i-1))); --求整数
            n1:=mod(n1,10**(i-1)); --求余数

          case n2
            when 0 then
              if (cccc IS NOT NULL) and (n0=0) and (n1!=0) then --当有第一个0且后面不全是0时,才写“零”
                    cccc:=cccc||'零';
              end if;
              n0:=n0+1;   
            
            when 1 then cccc:=cccc||'壹';n0:=0;
            when 2 then cccc:=cccc||'贰';n0:=0;
            when 3 then cccc:=cccc||'叁';n0:=0;
            when 4 then cccc:=cccc||'肆';n0:=0;
            when 5 then cccc:=cccc||'伍';n0:=0;
            when 6 then cccc:=cccc||'陆';n0:=0;
            when 7 then cccc:=cccc||'柒';n0:=0;
            when 8 then cccc:=cccc||'捌';n0:=0;
            when 9 then cccc:=cccc||'玖';n0:=0;
           end case;
          

           --2,为每一位数字加权
           if n2!=0 then   --取得的数字不为0才能加权
            case i
             when 1 then null;
             when 2 then cccc:=cccc||'拾';
             when 3 then cccc:=cccc||'百';
             when 4 then cccc:=cccc||'千';
             when 5 then cccc:=cccc||'万';
            end case;       
           end if;

        end loop;
        
        
      end if; --数字小于10万

    -------------------------------------------
      if cccc IS NOT NULL then
        :block2.item2:=cccc;
      else
          :block2.item2:='零';
      end if;
     end if;--转化小于1千万数  
    end;

  • 相关阅读:
    纯纯小白~学习python记录~用Django创建第一个项目
    mTLS: openssl创建CA证书
    关于Git使用:fatal: Could not read from remote repository.的报错问题解决
    夏天快乐的源泉
    MMDetection(四):在自己的数据集上训练模型
    WPSpell将拼写检查添加到VCL应用程序
    从零搭建react + webpack项目
    微软免费AI基础中文课程;马斯克提出撤诉OpenAI条件:“改名ClosedAI”
    leetcode1678:设计Goal解析器(11.6每日一题)
    Linux安装与卸载Jenkins
  • 原文地址:https://blog.csdn.net/zzjlhlcd/article/details/127705249