create or replace
function spell_number( p_number in number )
return varchar2
-- original by Tom Kyte
-- modified to include decimal places
as
type myArray is table of varchar2(255);
l_str myArray := myArray( '',
' thousand ', ' million ',
' billion ', ' trillion ',
' quadrillion ', ' quintillion ',
' sextillion ', ' septillion ',
' octillion ', ' nonillion ',
' decillion ', ' undecillion ',
' duodecillion ' );
l_num varchar2(50) default trunc( p_number );
l_return varchar2(4000);
begin
for i in 1 .. l_str.count
loop
exit when l_num is null;
if ( substr(l_num, length(l_num)-2, 3) <> 0 )
then
l_return := to_char(
to_date(
substr(l_num, length(l_num)-2, 3),
'J' ),
'Jsp' ) || l_str(i) || l_return;
end if;
l_num := substr( l_num, 1, length(l_num)-3 );
end loop;
l_return := l_return || ' Dhirams';
-- beginning of section added to include decimal places:
if to_char( p_number ) like '%.%'
then
l_num := substr( p_number, instr( p_number, '.' )+1 );
if l_num > 0
then
l_return := l_return || ' And ';
for i in 1 .. length (l_num)
loop
exit when l_num is null;
if substr( l_num, 1, 1 ) = '0'
then
l_return := l_return || ' zero';
else
l_return := l_return
|| ' '
|| to_char(
to_date(
substr( l_num, 1, 1),
'j' ),
'jsp' );
end if;
l_num := substr( l_num, 2 );
end loop;
-- L_Return := L_Return || ' ' || to_Char(To_Date(L_Num,'J'),'JSP');
end if;
end if;
-- end of section added to include decimal places
return l_return;
end spell_number;
No comments:
Post a Comment