实现阿拉伯数字变成中文大写

本文介绍了一个用于将数值金额转换为中文大写的PLSQL函数。该函数能够处理包含整数部分和小数部分的金额,并将其转换为符合中文会计习惯的大写形式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CREATE OR REPLACE FUNCTION printMoneylnZh(money number) RETURN VARCHAR2 IS
TYPE type_varchar2 is table of VARCHAR2(500);
m_string type_varchar2 := type_varchar2('分','角','圆','拾','佰','仟','','拾','佰','仟','','拾','佰','仟');
n_string type_varchar2 := type_varchar2('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
v_num NUMBER := 0;
f_money NUMBER;
int_money NUMBER;
money_length NUMBER;
f_money_length NUMBER;
money_chinese varchar2(10000) default null;
type n_table is table of NUMBER index by binary_integer;
n_money n_table;
BEGIN
select (money - floor(money))*100, trunc(money)
INTO f_money, int_money
from dual;
money_length := length(int_money);
select length(money) - money_length - 1 into f_money_length from dual;
IF f_money = 0 THEN
FOR i in reverse 1 .. money_length loop
v_num := v_num + 1;
SELECT trunc(int_money / power(10,i - 1), 0)
INTO n_money(v_num)
FROM dual;
IF n_money(v_num) = 0 THEN
IF substr(money_chinese, length(money_chinese), 1) != '零' THEN
money_chinese := money_chinese || n_string(n_money(v_num) + 1);
END IF;
else
money_chinese := money_chinese || n_string(n_money(v_num) + 1) ||
m_string(2 + i);
end if;
if i=9 then
money_chinese := rtrim(money_chinese, '零');
money_chinese := money_chinese ||'亿';
elsif i=5 then
money_chinese := rtrim(money_chinese, '零');
IF substr(money_chinese, length(money_chinese), 1) != '亿' THEN
money_chinese := money_chinese ||'万';
end if;
end if;
int_money := int_money - power(10, i - 1) * n_money(v_num);
end loop;
money_chinese := rtrim(money_chinese, '零') || '整';
dbms_output.put_line(money_chinese);
else
FOR i in reverse 1 .. money_length loop
v_num := v_num + 1;
SELECT trunc(int_money / power(10, i - 1), 0)
INTO n_money(v_num)
FROM dual;
IF n_money(v_num) = 0 THEN
IF substr(money_chinese, length(money_chinese), 1) != '零' THEN
money_chinese := money_chinese || n_string(n_money(v_num) + 1);
END IF;
else
money_chinese := money_chinese || n_string(n_money(v_num) + 1) ||
m_string(2 + i);
end if;
if i=9 then
money_chinese := rtrim(money_chinese, '零');
money_chinese := money_chinese ||'亿';
elsif i=5 then
money_chinese := rtrim(money_chinese, '零');
IF substr(money_chinese, length(money_chinese), 1) != '亿' THEN
money_chinese := money_chinese ||'万';
end if;
end if;
int_money := int_money - power(10, i - 1) * n_money(v_num);
end loop;
if f_money<10 then
money_chinese:=money_chinese||n_string(f_money+1)||'分';
else
if mod(f_money,10)=0 then
money_chinese:=money_chinese||n_string(f_money/10+1)||'角';
else
v_num:=0;
for i in reverse 1..f_money_length loop
v_num:=v_num+1;
SELECT trunc(f_money/power(10,i-1),0)INTO n_money(v_num) from dual;
money_chinese:=money_chinese||n_string(n_money(v_num)+1)||m_string(i);
f_money:=f_money-power(10,i-1)*n_money(v_num);
end loop;
end if;
end if;
end if;
RETURN money_chinese;
END;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值