create function inwords(n IN NUMBER) return varchar2
is
words varchar2(500);
begin
select distinct SUBSTR(' '||
DECODE(MOD(TRUNC(n/100000000,0),10),2,'Twenty ',
3,'Thirty ',
4,'Forty ',
5,'Fifty ',
6,'Sixty ',
7,'Seventy ',
8,'Eighty ',
9,'Ninety ',
1,DECODE(MOD(TRUNC(n/10000000,0),10),0,'Ten ',
1,'Eleven ',
2,'Twelve ',
3,'Thirteen ',
4,'Fourteen ',
5,'Fifteen ',
6,'Sixteen ',
7,'Seventeen ',
8,'Eighteen ',
9,'Nineteen ',''),'')
|| DECODE(MOD(TRUNC(n/100000000,0),10),1,'',
DECODE(MOD(TRUNC(n/10000000,0),10),1,'One ',
2,'Two ',
3,'Three ',
4,'Four ',
5,'Five ',
6,'Six ',
7,'Seven ',
8,'Eight ',
9,'Nine ', ''))
||
DECODE( MOD(TRUNC(n/10000000,0),10),
0,DECODE(MOD(TRUNC(n/10000000,0),10), 0,'','Crore '),'Crore ')
||
DECODE(MOD(TRUNC(n/1000000,0),10),2,'Twenty ',
3,'Thirty ',
4,'Forty ',
5,'Fifty ',
6,'Sixty ',
7,'Seventy ',
8,'Eighty ',
9,'Ninety ',
1,DECODE(MOD(TRUNC(n/100000,0),10),1,'Eleven ',
2,'Twelve ',
3,'Thirteen ',
4,'Fourteen ',
5,'Fifteen ',
6,'Sixteen ',
7,'Seventeen ',
8,'Eighteen ',
9,'Nineteen ',
0,'Ten ',''),'')
||
DECODE(MOD(TRUNC(n/1000000,0),10),1,'',
DECODE(MOD(TRUNC(n/100000,0),10),1,'One ',
2,'Two ',
3,'Three ',
4,'Four ',
5,'Five ',
6,'Six ',
7,'Seven ',
8,'Eight ',
9,'Nine ', ''))
||
DECODE(MOD(TRUNC(n/1000000,0),10),
0,DECODE(MOD(TRUNC(n/100000,0),10), 0,'','Lakh '),'Lakh ')
||
DECODE(MOD(TRUNC(n/10000,0),10),2,'Twenty ',
3,'Thirty ',
4,'Forty ',
5,'Fifty ',
6,'Sixty ',
7,'Seventy ',
8,'Eighty ',
9,'Ninety ',
1,DECODE(MOD(TRUNC(n/1000,0),10),1,'Eleven ',
2,'Twelve ',
3,'Thirteen ',
4,'Fourteen ',
5,'Fifteen ',
6,'Sixteen ',
7,'Seventeen ',
8,'Eighteen ',
9,'Nineteen ',
0,'Ten ',''), '')
||
DECODE(MOD(TRUNC(n/10000,0),10),1,'',
DECODE(MOD(TRUNC(n/1000,0),10),1,'One ',
2,'Two ',
3,'Three ',
4,'Four ',
5,'Five ',
6,'Six ',
7,'Seven ',
8,'Eight ',
9,'Nine ', ''))
||
DECODE(MOD(TRUNC(n/10000,0),10),0,
DECODE(MOD(TRUNC(n/1000,0),10), 0,'','thousand '),'thousand ')
||
DECODE(MOD(TRUNC(n/100,0),10),1,'One ',
2,'Two ',
3,'Three ',
4,'Four ',
5,'Five ',
6,'Six ',
7,'Seven ',
8,'Eight ',
9,'Nine ','')
||
DECODE(MOD(TRUNC(n/100,0),10),0,'','Hundred ')
||
DECODE(MOD(TRUNC(n/10,0),10),2,'Twenty ',
3,'Thirty ',
4,'Forty ',
5,'Fifty ',
6,'Sixty ',
7,'Seventy ',
8,'Eighty ',
9,'Ninety ',
1,DECODE(MOD(TRUNC(n,0),10),
1,'Eleven ',
2,'Twelve ',
3,'Thirteen ',
4,'Fourteen ',
5,'Fifteen ',
6,'Sixteen ',
7,'Seventeen ',
8,'Eighteen ',
9,'Nineteen ',
0,'Ten ',''),'')
||
DECODE(MOD(TRUNC(n/10,0),10),1,'',
DECODE(MOD(TRUNC(n,0),10),1,'One ',
2,'Two ',
3,'Three ',
4,'Four ',
5,'Five ',
6,'Six ',
7,'Seven ',
8,'Eight ',
9,'Nine ', ''))
||
DECODE(MOD(12434567,1),0,'','and ')
||
DECODE(MOD(TRUNC(n*10,0),10),2,'Twenty ',
3,'Thirty ',
4,'Forty ',
5,'Fifty ',
6,'Sixty ',
7,'Seventy ',
8,'Eighty ',
9,'Ninety ',
1,DECODE(MOD(TRUNC(n*100,0),10),
1,'Eleven ',
2,'Twelve ',
3,'Thirteen ',
4,'Fourteen ',
5,'Fifteen ',
6,'Sixteen ',
7,'Seventeen ',
8,'Eighteen ',
9,'Nineteen ',
0,'Ten ',''), '')
||
DECODE(MOD(TRUNC(n*10,0),10),1,'',
DECODE(MOD(TRUNC(n*100,0),10),1,'One ',
2,'Two ',
3,'Three ',
4,'Four ',
5,'Five ',
6,'Six ',
7,'Seven ',
8,'Eight ',
9,'Nine ', ''))
||
DECODE(MOD(n,1),0,'',' ')||'only ',1,120)
INTO words FROM DUAL;
return words;
end;
/