oracle 金額大寫轉換

2021-07-14 08:32:22 字數 2474 閱讀 1571

function convert_money(input_number number) return varchar2 is

i pls_integer;

snum varchar2(20) := ltrim(replace(to_char(abs(input_number), '9999999999999990.99'), '.'));

len pls_integer := length(snum);

sch varchar2(30) := '零壹貳叄肆伍陸柒捌玖';

sjin varchar2(60) := '分角圓拾佰仟萬拾佰仟億拾佰仟萬拾佰仟';

srmb varchar2(200) := '';

num pls_integer;

s_num pls_integer := 0; --'0'起始位置

e_num pls_integer := 0; --'0'結束位置

begin

if input_number is null then

return null;

end if;

for i in 1 .. len loop

num := to_number(substr(snum, i, 1));

if num <> 0 then

--非'0'時處理:

if s_num = 0 then

srmb := srmb || substr(sch, num + 1, 1) || substr(sjin, len - i + 1, 1); --前面字元非'0', 正常聯接...

else

srmb := srmb || --否則:

case

when s_num = e_num then --前面只有乙個'0'

case s_num

when 7 then

'萬' --只處理進製

when 11 then

'億'when 15 then

'萬'end

when e_num < 12 then --否則(多個'0'處理)

case

when s_num < 7 then

'' --萬以內..

when s_num < 11 then

case

when e_num < 8 and s_num < 10 then

'萬'end

when s_num < 15 then

case

when e_num < 12 then

'億'end

else

'萬億'

endwhen e_num < 16 and s_num > 14 then

'萬'end || case

when s_num > 3 and e_num < 3 then

'圓零'

when e_num = 3 then

'圓'when e_num not in (7, 11, 15) or s_num - e_num > 2 then

'零'end;

srmb := srmb || substr(sch, num + 1, 1) || substr(sjin, len - i + 1, 1);

end if;

s_num := 0;

e_num := 0;

else

if s_num = 0 then

--當s_num = 0時'0'串起始,

s_num := len - i + 1; --記錄開始

e_num := s_num; --各結整位置。

else

e_num := len - i + 1; --否則新的結整位置。

end if;

end if;

end loop;

if s_num <> 0 then

--此時以'0'結尾

srmb := srmb || case

when s_num = len then

'零圓整' --全'0'串,加...

when s_num = 1 or s_num = 2 then

'整' --分(1),角(2)後加...

when s_num < 7 or s_num = 10 then

'圓整'

when s_num < 11 then

'萬圓整'

when s_num < 15 then

'億圓整'

else

'萬億圓整'

end;

else

srmb := srmb || '整'; --不以'0'結尾,加...

end if;

if input_number < 0 then

srmb := '負' || srmb;

end if;

return srmb;

end;

金額大寫轉換

use toy go object storedprocedure dbo l2u script date 03 19 2014 13 15 27 set ansi nulls on goset quoted identifier on goalter procedure dbo l2u n low...

Python金額大寫轉換

判斷是否包含小數點,還有判斷是否只包含小數點和數字的這邊沒寫出來 def is contain dot check str check str str check str for ch in check str if ch return true return false def digital t...

小寫金額轉換為大寫金額

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