Oracle 小写金额转换为大写

在开发EBS的合同报表打印的时候需要将小写金额转换为大写。

如下是本人自己写的转换函数。

主要思路:先获取小数点位置,在区分整数与小数点处理,根据位数和数字组合读取金额。

最后再处理特殊显示部分。

/*******************************************************************

*  FUNCTION get_big_amount 数字金额转换为大写

*  p_amount 输入数据金额

*  返回大写金额,位数 :千亿----厘

********************************************************************/

FUNCTION get_big_amount(p_amount IN NUMBER) RETURN VARCHAR2

IS

smallmoney VARCHAR2(25);

bigwrite   VARCHAR2(200);

bignum     VARCHAR2(4);

rmb        VARCHAR2(4);

moneyplace NUMBER;

dotplace   NUMBER;

moneynum   NUMBER;

BEGIN

IF p_amount < 0 OR p_amount > 999999999999.9999 then  -- 0 - 千亿

bigwrite := ‘转换金额超出计算范围.‘;

RETURN bigwrite;

END IF;

IF p_amount = 0 THEN

bigwrite := ‘零圆.‘;

RETURN bigwrite;

END IF;

smallmoney := p_amount;

dotplace := instr(smallmoney,‘.‘);--得出小数点的位置

IF dotplace = 0 THEN

moneyplace := length(smallmoney);--整数的位数

ELSE

moneyplace := dotplace - 1;

END IF;

FOR moneynum IN 1..length(smallmoney) LOOP

IF moneynum < dotplace THEN             --有小数点的前半部分处理

CASE (substr(smallmoney,moneynum,1))  --从左往右,高位开始读,判断转换数字

WHEN ‘1‘ THEN bignum := ‘壹‘;

WHEN ‘2‘ THEN bignum := ‘贰‘;

WHEN ‘3‘ THEN bignum := ‘叁‘;

WHEN ‘4‘ THEN bignum := ‘肆‘;

WHEN ‘5‘ THEN bignum := ‘伍‘;

WHEN ‘6‘ THEN bignum := ‘陆‘;

WHEN ‘7‘ THEN bignum := ‘柒‘;

WHEN ‘8‘ THEN bignum := ‘捌‘;

WHEN ‘9‘ THEN bignum := ‘玖‘;

WHEN ‘0‘ THEN bignum := ‘零‘;    --‘零’

END CASE;

CASE moneyplace                  --高位开始读,判断位数

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 := ‘佰‘;

WHEN 12 THEN rmb := ‘仟‘;  --千亿

ELSE null;

END CASE;

moneyplace := moneyplace - 1;           --位数递减

bigwrite := bigwrite || bignum || rmb;  --组合读取

ELSIF moneynum = dotplace THEN

bigwrite := bigwrite || ‘‘;   --‘点’

ELSE                                    --无小数点全整数处理 与 有小数点的后半部分处理

CASE (substr(smallmoney,moneynum,1))

WHEN ‘1‘ THEN bignum := ‘壹‘;

WHEN ‘2‘ THEN bignum := ‘贰‘;

WHEN ‘3‘ THEN bignum := ‘叁‘;

WHEN ‘4‘ THEN bignum := ‘肆‘;

WHEN ‘5‘ THEN bignum := ‘伍‘;

WHEN ‘6‘ THEN bignum := ‘陆‘;

WHEN ‘7‘ THEN bignum := ‘柒‘;

WHEN ‘8‘ THEN bignum := ‘捌‘;

WHEN ‘9‘ THEN bignum := ‘玖‘;

WHEN ‘0‘ THEN bignum := ‘零‘;  --‘零’

END CASE;

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 := ‘佰‘;

WHEN 12 THEN rmb := ‘仟‘;  --千亿

ELSE rmb := null;

END CASE;

moneyplace := moneyplace - 1;

bigwrite := bigwrite || bignum||rmb;

END IF;

END LOOP;

--大写显示处理

IF bigwrite IS NOT NULL THEN

bigwrite := REPLACE(bigwrite, ‘零拾‘, ‘零‘);

bigwrite := REPLACE(bigwrite, ‘零佰‘, ‘零‘);

bigwrite := REPLACE(bigwrite, ‘零仟‘, ‘零‘);

bigwrite := REPLACE(bigwrite, ‘零零零‘, ‘零‘);

bigwrite := REPLACE(bigwrite, ‘零零‘, ‘零‘);

--  bigwrite := REPLACE(bigwrite, ‘零角零分零厘‘, ‘整‘);

--  bigwrite := REPLACE(bigwrite, ‘零厘‘, ‘整‘);

bigwrite := REPLACE(bigwrite, ‘零角‘, ‘零‘);

bigwrite := REPLACE(bigwrite, ‘零亿零萬零圆‘, ‘亿圆‘);

bigwrite := REPLACE(bigwrite, ‘亿零萬零圆‘, ‘亿圆‘);

bigwrite := REPLACE(bigwrite, ‘零亿零萬‘, ‘亿‘);

bigwrite := REPLACE(bigwrite, ‘零萬零圆‘, ‘萬圆‘);

bigwrite := REPLACE(bigwrite, ‘萬零圆‘, ‘萬圆‘);

bigwrite := REPLACE(bigwrite, ‘零亿‘, ‘亿‘);

bigwrite := REPLACE(bigwrite, ‘零萬‘, ‘萬‘);

bigwrite := REPLACE(bigwrite, ‘零圆‘, ‘圆‘);

bigwrite := REPLACE(bigwrite, ‘零零‘, ‘零‘);

END IF;

--壹元以下处理

bigwrite := LTRIM(LTRIM(LTRIM(LTRIM(LTRIM(bigwrite, ‘圆‘), ‘零‘), ‘角‘), ‘分‘), ‘厘‘);

IF bigwrite = ‘圆‘ THEN

bigwrite := ‘零圆‘;

END IF;

RETURN(bigwrite);

END get_big_amount;

--------------------------------------------------------------------

时间: 2024-10-13 22:17:00

Oracle 小写金额转换为大写的相关文章

C#:小写金额转换为大写

#region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; if (Math.Abs(Currnum) < 1e-20) return "零圆整"; if (Currnum < 1e-20) sResult = "负"; sResult = sResult + StringToChnNum(Math.Abs(Mat

java将小写金额转换为大写的工具类

public class Tool {             private static final String UNIT = "万千佰拾亿千佰拾万千佰拾元角分";         private static final String DIGIT = "零壹贰叁肆伍陆柒捌玖";         private static final double MAX_VALUE = 9999999999999.99D;         public static St

人民币 小写金额转换为大写金额

### 人民币 小写金额转换为大写金额 标签(空格分隔): 人民币 小写金额转换为大写金额 --- jsp:```div class="form-group"><label class="col-sm-4 control-label">合计人民币金额(小写):</label><div class="col-sm-7"><input id="totalRmbLower" type=

小写金转换为大写

<body><input type="text" id="txt"/><br/><input type="button" id="ss" value="submit"/><br/><input type="text" id="result"/></body><script typ

汇编-小写字母转换为大写字母

一.实习题目:小写字母转换为大写字母 二.实习目的:  1.掌握分支程序设计方法 2.了解小写字母和大写字母在计算机中的表示方法并显示. 三.代码:   data segment A db 'a'; B db 'z'; C db 00h; bb db 0ah,0dh,'$' string db 0ah,0dh,'The input num is not a case letter','$'; data ends code segment assume DS:data,CS:code star

C# 把小写人民币转换为大写

/// <summary> /// 转换人民币大小金额 /// </summary> /// <param name="num">金额</param> /// <returns>返回大写形式</returns> public static string CmycurD(decimal num) { string str1 = "零壹贰叁肆伍陆柒捌玖"; //0-9所对应的汉字 string st

JS实现将数字金额转换为大写人民币汉字

function convertCurrency(money) { //汉字的数字 var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); //基本单位 var cnIntRadice = new Array('', '拾', '佰', '仟'); //对应整数部分扩展单位 var cnIntUnits = new Array('', '万', '亿', '兆'); //对应小数部分单位 var cnDe

将小写字母转换为大写字母

var pinyin = (function () { var Pinyin = function (ops) { this.initialize(ops); }, options = { checkPolyphone: false, charcase: 'default' }; Pinyin.fn = Pinyin.prototype = { init: function (ops) { this.options = extend(options, ops); }, initialize: f

SQL标量值函数:小写金额转大写

我们日常开发业务系统中,作为统计报表中,特别是财务报表,显示中文金额经常遇到. 转换大小写的方法有很多,以下是从数据库函数方面解决这一问题. 效果如图: 调用:SELECT dbo.[Fn_ConvertRMB](192.4) 具体函数如下: -- ============================================= -- 调用:SELECT dbo.[Fn_ConvertRMB](192.4) -- Create date: 2015-01-06 -- Descripti