PL SQL 將小寫的金額轉換為大寫

2021-08-31 20:06:59 字數 2236 閱讀 5611

create or replace function smalltobig(smallmoney in varchar2)

return varchar2 is

dotplace number(2); --小數點位置

uppercase varchar2(60); --大寫方式

rmb varchar2(3); --rmb的單位

bignum varchar2(2); --大寫數字

moneyplace number(2); --數字的位置

moneynum number(14); --人民幣的位數

moneylen number(14); --數字位數

myexception exception; --自定義異常

begin

/*確定小數點的位置*/

dotplace := instr(smallmoney, '.');

moneylen := length(smallmoney);

if moneylen > 14 or (moneylen > 12 and dotplace = 0) then

raise myexception; --拋出自定義異常

end if;

/**確定人民幣的精度*/

if dotplace = 0 then

moneyplace := 0;

else

moneyplace := dotplace - moneylen;

end if;

for moneynum in reverse 1 .. moneylen 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 := '玖';

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 := '仟';

end case;

moneyplace := moneyplace + 1;

if bignum is null then

uppercase := bignum || rmb;

else

uppercase := bignum || rmb || uppercase;

end if;

end if;

end loop;

dbms_output.put_line(uppercase);

return uppercase;

end;

小寫金額轉換為大寫金額

我的乙個朋友寫的,金額轉成大寫 public static string convertmoney decimal dnum string str2 new string string strunit string.join str1 string struppernum string.join s...

小寫金額轉換為大寫金額

在很多地方都有用到將小寫金額轉換為大寫金額,就是將類似1234.56轉換為壹仟貳佰叄拾肆圓伍角陸分。到底要怎樣實現呢?其實只要仔細注意自己到底是怎麼讀的,細細揣摩一下。1 在千位 壹仟 2 在百位 貳佰.所以有兩個過程 1.講阿拉伯數字轉換為大寫數字。2.在各位後面加上諸如 萬 仟 佰 拾 圓 分 ...

將小寫金額轉換為英文大寫的SQL函式

createfunction dbo f num eng numnumeric 15,2 returnsvarchar 400 withencryption asbegin sqldeclare iint,hundredsint,tenthint,oneint declare thousandint...