金额大小写转换(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;
轉載于:https://www.cnblogs.com/accumulater/p/6145160.html
總結
以上是生活随笔為你收集整理的金额大小写转换(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python协程:从yield/send
- 下一篇: 说说程序员、编译器、CPU之间的三角恋