السلام عليكم
create OR REPLACE FUNCTION formatnumber (no number,type number,des varchar2) RETURN varchar2 IS
t varchar2(3);
desc1 varchar2(200);
desc2 varchar2(200);
desc3 varchar2(200);
desc4 varchar2(200);
p varchar2(10);
a varchar2(2);
n number;
BEGIN
desc4:=des;
t:=lpad(to_char(no),3,'0');
a:=substr(t,1,1);
select decode(a,'0',null,
'1','مائة',
'2','مائتان ',
'3','ثلاثة مائة',
'4','اربعمائة',
'5','خمسة مائة',
'6','ستة مائة',
'7','سبعة مائة',
'8','ثمانيمائة',
'9','تسعة مائة')
into desc1
from dual;
a:=substr(t,2,2);
if a<> '00' then
a:=substr(t,2,1);
select decode(a,'0',null,
'1','عشرة',
'2','عشرون',
'3','ثلاثون',
'4','اربعون',
'5','خمسون',
'6','ستون',
'7','سبعون',
'8','ثمانون',
'9','تسعون')
into desc2
from dual;
a:=substr(t,3,1);
select decode(a,'0',null,
'1','واحد',
'2','اثنين',
'3','ثلاثة',
'4','اربعة',
'5','خمسة',
'6','ستة',
'7','سبعة',
'8','ثمانية',
'9','تسعة')
into desc3
from dual;
if substr(t,2,1) = '1' and substr(t,3,1)= '1' then
desc3 := 'إحدى';
elsif substr(t,2,1) = '1' and substr(t,3,1) = '2' then
desc3 := 'اثنا';
end if;
end if;
-----------------------------------------------------------------------------
if desc4 is not null and desc1 is not null then
desc4 := desc4||' و'||desc1;
elsif desc4 is null and desc1 is not null then
desc4 := desc1;
end if;
if not (t in('001','002') and type in (1,2,3)) then
if desc4 is not null and desc3 is not null then
desc4 := desc4||' و'||desc3;
elsif desc4 is null and desc3 is not null then
desc4 := desc3;
end if;
end if;
if desc4 is not null and desc2 is not null then
if substr(t,2,1) <> '1' then
desc4 := desc4||' و'||desc2;
elsif substr(t,2,1) ='1' and substr(t,3,1) ='0' then
desc4 := desc4||' و'||desc2;
else
desc4 := desc4||desc2;
end if;
elsif desc4 is null and desc2 is not null then
desc4 := desc2;
end if;
n :=to_number(substr(t,1,3));
if type = 1 then
if n=1 or n>=11 then
p := 'بليون';
elsif n=2 then
p := 'بليونان';
else
p := 'بلايين';
end if;
elsif type = 2 then
if n = 1 or n >= 11 then
p := 'مليون';
elsif n = 2 then
p := 'مليونان';
else
p := 'ملايين';
end if;
elsif type = 3 then
if n=1 or n>=11 then
p := 'ألف';
elsif n=2 then
p := 'ألفان';
else
p := 'آلاف';
end if;
end if;
desc4 := desc4 ||' '||p;
return(desc4);
END;create the above function first .
create OR REPLACE FUNCTION no2txt(x number)
RETURN varchar2 IS
dsc varchar2(200);
d varchar2(100);
a number;
no number;
w number;
ln number;
BEGIN
d := to_char(x);
ln := length(d);
w := instr(d,'.',1);
if w <> 0 then
a := w-1;
elsif w = 0 then
a := ln;
end if;
if a <= 12 then
no := trunc(X * 0.000000001);
if no >= 1 then
dsc := formatnumber(no,1,dsc);
end if;
no := trunc((X * 0.000000001 - trunc(X * 0.000000001)) * 1000) ;
if no >= 1 then
dsc := formatnumber(no,2,dsc);
end if;
no := trunc((X * 0.000001 - trunc(X * 0.000001)) * 1000) ;
if no >= 1 then
dsc := formatnumber(no,3,dsc);
end if;
no := trunc((X * 0.001 - trunc(X * 0.001)) * 1000) ;
if no >= 1 then
dsc := formatnumber(no,4,dsc);
end if;
if dsc is not null then
dsc := dsc||' دينار';
end if;
no := trunc((X - trunc(X)) *100);
if no > 0 then
dsc := formatnumber(no,4,dsc)||' قرش';
end if;
return(dsc||' فقط لا غير.');
end if;
END;
create the above function
ثم جرب
select (555) from dual