金额大小写转换(1)
create or replace function smalltobig(smallmoney varchar2)
return varchar2 is
bigwrite varchar2(54); --用于返回大寫的錢數(shù)
bignum varchar2(2); --用于存放每一個阿拉伯?dāng)?shù)字對應(yīng)的漢字
rmb varchar2(2); --用于存放人民幣單位
moneyplace number; --用于確定人民幣的精度,最多只能精確到分
dotplace number; --確定小數(shù)點(diǎn)的位置
moneynum number; --人民幣的位數(shù)
myexception exception; --自定義異常
begin
/*用內(nèi)置函數(shù)INSTR確定小數(shù)點(diǎn)的位置*/
dotplace := instr(smallmoney, '.');
/*判斷是否超出本函數(shù)定義的精度范圍,
如果是則引發(fā)自定義異常myexception*/
if (length(smallmoney) > 14)
or ((length(smallmoney) > 12) and (dotplace = 0)) then
raise myexception;
end if;
/*確定人民幣的精度,如果小數(shù)點(diǎn)位置為0則精度只精確到元否則按小數(shù)點(diǎn)的 位置來確定人民幣的精度*/
if dotplace = 0 then
moneyplace := 0;
else
moneyplace := dotplace - length(smallmoney);
end if;
/*確定人民幣的精確,如果小數(shù)點(diǎn)位置為0則精度只精確到元否則按小數(shù)點(diǎn)的 位置來確定人民幣的精度*/
if dotplace = 0 then
moneyplace := 0;
else
moneyplace := dotplace - length(smallmoney);
end if;
/*通過一個FOR循環(huán)將smallmoney中的阿拉伯?dāng)?shù)字逐一去出來,注意該FOR循 環(huán)是按照降序循環(huán)的*/
for moneynum in reverse 1 .. length(smallmoney)
loop
/*如果位置在小數(shù)點(diǎn)的位置則不做任何動作*/
if moneynumdotplace then
/*CASE循環(huán)將smallmoney里對應(yīng)的阿拉伯?dāng)?shù)字用漢語來表示*/
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循環(huán)來設(shè)置smallmoney里對應(yīng)的阿拉伯?dāng)?shù)字的相應(yīng)的精度*/
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('該函數(shù)只能轉(zhuǎn)換長度不大于14位后整數(shù)位不大于12位的錢數(shù)!');
when others then
dbms_output.put_line('不是有效的錢數(shù)!');
end;
轉(zhuǎn)載于:https://www.cnblogs.com/accumulater/p/6145160.html
總結(jié)
以上是生活随笔為你收集整理的金额大小写转换(1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python协程:从yield/send
- 下一篇: 说说程序员、编译器、CPU之间的三角恋