当前位置: 首页 > news >正文

金额大小写转换(1)


create   or   replace   function  smalltobig( smallmoney   varchar2 )

 
return   varchar2   is

    bigwrite 
varchar2 ( 54 );  -- 用于返回大写的钱数

    bignum 
varchar2 ( 2 );  -- 用于存放每一个阿拉伯数字对应的汉字

    rmb 
varchar2 ( 2 );  -- 用于存放人民币单位

    moneyplace 
number -- 用于确定人民币的精度,最多只能精确到分

    dotplace 
number -- 确定小数点的位置

    moneynum 
number -- 人民币的位数

    myexception exception; 
-- 自定义异常

begin

    
/* 用内置函数INSTR确定小数点的位置 */

    dotplace :
=  instr( smallmoney ' . ' );

    
/* 判断是否超出本函数定义的精度范围,
    
    如果是则引发自定义异常myexception
*/

    
if  (length( smallmoney >   14 )
      
       
or  ((length( smallmoney >   12 and  (dotplace  =   0 ))  then
    
        raise myexception;
    
    
end   if ;

    
/* 确定人民币的精度,如果小数点位置为0则精度只精确到元否则按小数点的 位置来确定人民币的精度 */

    
if  dotplace  =   0   then
    
        moneyplace :
=   0 ;
    
    
else
    
        moneyplace :
=  dotplace  -  length( smallmoney );
    
    
end   if ;

    
/* 确定人民币的精确,如果小数点位置为0则精度只精确到元否则按小数点的 位置来确定人民币的精度 */

    
if  dotplace  =   0   then
    
        moneyplace :
=   0 ;
    
    
else
    
        moneyplace :
=  dotplace  -  length( smallmoney );
    
    
end   if ;

    
/* 通过一个FOR循环将smallmoney中的阿拉伯数字逐一去出来,注意该FOR循 环是按照降序循环的 */

    
for  moneynum  in   reverse   1  .. length( smallmoney )
    loop
    
        
/* 如果位置在小数点的位置则不做任何动作 */
    
        
if  moneynumdotplace  then
        
            
/* CASE循环将smallmoney里对应的阿拉伯数字用汉语来表示 */
        
            
case  substr( smallmoney , moneynum,  1 )
            
                
when   ' 1 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 2 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 1 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 2 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 1 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 2 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 1 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 2 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 1 '   then
                    bignum :
=   ' ' ;
                
                
when   ' 2 '   then
                    bignum :
=   ' ' ;
                
            
end   case ;
        
            
/* CASE循环来设置smallmoney里对应的阿拉伯数字的相应的精度 */
        
            
case  moneyplace
            
                
when   ' -2 '   then
                    rmb :
=   ' '   when   ' -1 '   then  rmb : =   ' ' ;
                
                
when   ' 0 '   then
                    rmb :
=   ' '   when   ' 1 '   then  rmb : =   ' ' ;
                
                
when   ' 2 '   then
                    rmb :
=   ' '   when   ' 3 '   then  rmb : =   ' ' ;
                
                
when   ' 4 '   then
                    rmb :
=   ' '   when   ' 5 '   then  rmb : =   ' ' ;
                
                
when   ' 6 '   then
                    rmb :
=   ' '   when   ' 7 '   then  rmb : =   ' ' ;
                
                
when   ' 8 '   then
                    rmb :
=   ' 亿 '   when   ' 9 '   then  rmb : =   ' ' ;
                
                
when   ' 10 '   then
                    rmb :
=   ' '   when   ' 11 '   then  rmb : =   ' ' ;
                
            
end   case ;
        
            moneyplace :
=  moneyplace  +   1 ;
        
            
if  bigwrite  is   null   then
            
                bigwrite :
=  bignumrmb;
            
            
else
            
                bigwrite :
=  bignumrmbbigwrite;
            
            
end   if ;
        
        
end   if ;
    
    
end  loop;

    
return  bigwrite;

exception
    
-- 异常处理部分

    
when  myexception  then
    
        dbms_output.put_line(
' 该函数只能转换长度不大于14位后整数位不大于12位的钱数! ' );
    
    
when  others  then
    
        dbms_output.put_line(
' 不是有效的钱数! ' );
    
end ;


相关文章:

  • LaPlayer(1)------Service浅析
  • bouml简介与使用总结
  • Oracle的隐式转换
  • 在同一个页面父窗口打开子窗口,动态无刷新提交,超炫基于jquery ajax提交,兼容IE7+,火狐.....
  • PHP统计目录下的文件总数及代码行数(去除注释及空行)
  • nyoj 523 双向广搜
  • JS调用后台方法大全
  • 即时通信3
  • frame-relay实验
  • eclipse启动不了报错java was started but returned exit code=13
  • GDAL编译Windows平台下64位的方式
  • java调用webservice
  • 使用JSR234实现对图片的缩放
  • 《大型分布式网站架构设计与实践》
  • 迷路
  • Docker 笔记(1):介绍、镜像、容器及其基本操作
  • Javascript基础之Array数组API
  • Linux后台研发超实用命令总结
  • Mithril.js 入门介绍
  • Ruby 2.x 源代码分析:扩展 概述
  • select2 取值 遍历 设置默认值
  • SpiderData 2019年2月25日 DApp数据排行榜
  • 半理解系列--Promise的进化史
  • 从0到1:PostCSS 插件开发最佳实践
  • 从0实现一个tiny react(三)生命周期
  • 从伪并行的 Python 多线程说起
  • 盘点那些不知名却常用的 Git 操作
  • 前端之React实战:创建跨平台的项目架构
  • 悄悄地说一个bug
  • 视频flv转mp4最快的几种方法(就是不用格式工厂)
  • 微信小程序:实现悬浮返回和分享按钮
  • 为什么要用IPython/Jupyter?
  • PostgreSQL 快速给指定表每个字段创建索引 - 1
  • ![CDATA[ ]] 是什么东东
  • #pragma pack(1)
  • (27)4.8 习题课
  • (JSP)EL——优化登录界面,获取对象,获取数据
  • (备忘)Java Map 遍历
  • (附源码)php投票系统 毕业设计 121500
  • (蓝桥杯每日一题)平方末尾及补充(常用的字符串函数功能)
  • .bat批处理(八):各种形式的变量%0、%i、%%i、var、%var%、!var!的含义和区别
  • .NET/C# 推荐一个我设计的缓存类型(适合缓存反射等耗性能的操作,附用法)
  • .NET和.COM和.CN域名区别
  • :如何用SQL脚本保存存储过程返回的结果集
  • @ 代码随想录算法训练营第8周(C语言)|Day57(动态规划)
  • @EnableWebMvc介绍和使用详细demo
  • [20150629]简单的加密连接.txt
  • [android] 看博客学习hashCode()和equals()
  • [AR Foundation] 人脸检测的流程
  • [Asp.net MVC]Asp.net MVC5系列——Razor语法
  • [BT]BUUCTF刷题第9天(3.27)
  • [CVPR2021]Birds of a Feather: Capturing Avian Shape Models from Images
  • [DAX] MAX函数 | MAXX函数
  • [Django 0-1] Core.Checks 模块
  • [Flutter]打包IPA