Fungsi ini berfungsi untuk mengkonversi number ke terbilang , biasanya banyak di pakai untuk mencetak billing statement .
Berikut ini contoh script sederhana yang saya buat :
# Author : Ida Bagus Enderajana
# Website : http://zmp165.blogspot.com/
Create or Replace Function Terbilang(Digit varchar2) Return Varchar2 is
Tampung99 varchar2(100);
kel_1 varchar2(30);
kel_2 varchar2(30);
kel_3 varchar2(30);
kel_4 varchar2(30);
kel_5 varchar2(30);
hasil varchar2(3000);
cekdigit number;
sisabagi number;
Begin
tampung99 :='';
kel_1:='';
kel_2:='';
kel_3:='';
kel_4:='';
kel_5:='';
cekdigit :=length(digit);
sisabagi :=mod(cekdigit,3);
if sisabagi=0 then
tampung99:=digit;
elsif sisabagi=1 then
tampung99:='00'||digit;
elsif sisabagi=2 then
tampung99:='0'||digit;
end if;
if length(tampung99)=3 then
kel_1:=substr(tampung99,1,3);
hasil:=basecurr_triple_number_words(kel_1);
elsif length(tampung99)=6 then
kel_1:=substr(tampung99,1,3);
kel_2:=substr(tampung99,4,3);
if kel_1='001' and kel_2='000' then
hasil:='seribu';
elsif kel_1=('001') and kel_2 <>('000') then
hasil:='seribu '||basecurr_triple_number_words(to_number(kel_2));
elsif kel_1 <>('001') and kel_2 <>('000') then
hasil:=basecurr_triple_number_words(to_number(kel_1))||' ribu '||basecurr_triple_number_words(to_number(kel_2));
elsif kel_1 <>'001' and kel_2='000' then
hasil:=basecurr_triple_number_words(to_number(kel_1))||' ribu ';
end if;
elsif length(tampung99)=9 then
begin
kel_1:=substr(tampung99,1,3);
kel_2:=substr(tampung99,4,3);
kel_3:=substr(tampung99,7,3);
if kel_1 <>'000' then
begin
if kel_2 <>'000' and kel_2 <>'001' and kel_3 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' juta '||basecurr_triple_number_words(kel_2)||' ribu '||basecurr_triple_number_words(kel_3);
elsif kel_2 ='000' and kel_3='000' then
hasil:=basecurr_triple_number_words(kel_1)||' juta '||basecurr_triple_number_words(kel_3);
elsif kel_2='000' and kel_3 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' juta '||basecurr_triple_number_words(kel_3);
elsif kel_2='001' and kel_3='000' then
hasil:=basecurr_triple_number_words(to_number(kel_1))||' juta '||' seribu';
elsif kel_2='001' and kel_3 <>'000' then
hasil:=basecurr_triple_number_words(to_number(kel_1))||' juta '||' seribu '||basecurr_triple_number_words(to_number(kel_3));
elsif kel_2 ='001' and kel_3 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' juta '||' seribu '||basecurr_triple_number_words(kel_3);
elsif kel_2 <>'000' and kel_2 <>'001' and kel_3 <>'000' or kel_3='000' then
hasil:=basecurr_triple_number_words(kel_1)||' juta '||basecurr_triple_number_words(kel_2)||' ribu '||basecurr_triple_number_words(kel_3);
end if;
end;
end if;
end;
elsif length(tampung99)=12 then
begin
kel_1:=substr(tampung99,1,3);
kel_2:=substr(tampung99,4,3);
kel_3:=substr(tampung99,7,3);
kel_4:=substr(tampung99,10,3);
if kel_1 <>'000' and kel_2 <>'000' then
begin
if kel_3 <>'000' and kel_4 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_2)||' juta '||basecurr_triple_number_words(kel_3)||' ribu '||basecurr_triple_number_words(kel_4);
elsif kel_3 ='000' and kel_4 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_2)||' juta '||basecurr_triple_number_words(kel_4);
elsif kel_3 ='000' and kel_4='000' then
hasil:=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_2)||' juta '||basecurr_triple_number_words(kel_4);
elsif kel_3='001' and kel_4='000' then
hasil:=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_2)||' juta '||' seribu ';
elsif kel_3='001' and kel_4 <>'000' then
hasil :=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_2)||' juta '||' seribu '||basecurr_triple_number_words(kel_4);
elsif kel_3 <>'000' and kel_3 ='001' and kel_4 <>'000' or kel_4='000' then
hasil :=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_2)||' juta '||basecurr_triple_number_words(kel_3)||' ribu '||basecurr_triple_number_words(kel_4);
end if;
end;
elsif kel_1 <>'000' and kel_2='000' then
begin
if kel_3 ='000' and kel_4='000' or kel_4 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_4);
elsif kel_3 <>'001' or kel_3 <>'000' and kel_4 ='000' or kel_4 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' milyar '||basecurr_triple_number_words(kel_3)||' ribu '||basecurr_triple_number_words(kel_4);
end if;
end;
end if;
end;
elsif length(tampung99)=15 then
begin
kel_1:=substr(tampung99,1,3);
kel_2:=substr(tampung99,4,3);
kel_3:=substr(tampung99,7,3);
kel_4:=substr(tampung99,10,3);
kel_5:=substr(tampung99,13,3);
if kel_1 <>'000' and kel_2 <>'000' and kel_3 <>'000' then
begin
if kel_4 <>'000' and kel_5 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_4)||' ribu '||basecurr_triple_number_words(kel_5);
elsif kel_4 ='000' and kel_5 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_5);
elsif kel_4 ='000' and kel_5='000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_5);
elsif kel_4='001' and kel_5='000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_3)||' juta '||' seribu ';
elsif kel_4='001' and kel_5 <>'000' then
hasil :=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_3)||' juta '||' seribu '||basecurr_triple_number_words(kel_5);
elsif kel_4 <>'000' and kel_4 ='001' and kel_5 <>'000' or kel_5='000' then
hasil :=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_4)||' ribu '||basecurr_triple_number_words(kel_5);
end if;
end;
elsif kel_1 <>'000' and kel_2 <>'000' and kel_3 ='000' then
begin
if kel_4 <>'000' and kel_5 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_4)||' ribu '||basecurr_triple_number_words(kel_5);
elsif kel_4 ='000' and kel_5 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_5);
elsif kel_4 ='000' and kel_5='000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_5);
elsif kel_4='001' and kel_5='000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||' seribu ';
elsif kel_4='001' and kel_5 <>'000' then
hasil :=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||' seribu '||basecurr_triple_number_words(kel_5);
elsif kel_4 <>'000' and kel_4 ='001' and kel_5 <>'000' or kel_5='000' then
hasil :=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_2)||' milyar '||basecurr_triple_number_words(kel_4)||' ribu '||basecurr_triple_number_words(kel_5);
end if;
end;
elsif kel_1 <>'000' and kel_2 ='000' and kel_3 <>'000' then
begin
if kel_4 <>'000' and kel_5 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_4)||' ribu '||basecurr_triple_number_words(kel_5);
elsif kel_4 ='000' and kel_5 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_5);
elsif kel_4 ='000' and kel_5='000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_5);
elsif kel_4='001' and kel_5='000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_3)||' juta '||' seribu ';
elsif kel_4='001' and kel_5 <>'000' then
hasil :=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_3)||' juta '||' seribu '||basecurr_triple_number_words(kel_5);
elsif kel_4 <>'000' and kel_4 ='001' and kel_5 <>'000' or kel_5='000' then
hasil :=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_3)||' juta '||basecurr_triple_number_words(kel_4)||' ribu '||basecurr_triple_number_words(kel_5);
end if;
end;
elsif kel_1 <>'000' and kel_2='000' and kel_3='000' then
begin
if kel_3 ='000' and kel_4='000' or kel_4 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_5);
elsif kel_3 <>'001' or kel_3 <>'000' and kel_4 ='000' or kel_4 <>'000' then
hasil:=basecurr_triple_number_words(kel_1)||' trilyun '||basecurr_triple_number_words(kel_4)||' ribu '||basecurr_triple_number_words(kel_5);
end if;
end;
end if;
end;
end if;
return(hasil);
end;
/
No comments:
Post a Comment