Home » SQL & PL/SQL » SQL & PL/SQL » How this function works??
icon1.gif  How this function works?? [message #245130] Fri, 15 June 2007 04:42 Go to next message
sibgat
Messages: 45
Registered: November 2006
Location: Chennai
Member

Hi,
Below is the code i found in net, to spell number, can anyone help me to understand it completely.. since i am unable to understand the logic.

Thanks in advance
Sib

create or replace function spell_number( p_number in number )  return varchar2
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;
     return l_return;
   end;
   
Re: How this function works?? [message #245137 is a reply to message #245130] Fri, 15 June 2007 05:02 Go to previous messageGo to next message
Michel Cadot
Messages: 64120
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This is on AskTom, Spell the number thread.
Please always tell where you get something.

Read the thread and come back if you don't understand something.
Before read "Datetime Format Models" section in SQL Reference.

Regards
Michel



Re: How this function works?? [message #245139 is a reply to message #245137] Fri, 15 June 2007 05:03 Go to previous messageGo to next message
sibgat
Messages: 45
Registered: November 2006
Location: Chennai
Member

From the below site

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1407603857650
Re: How this function works?? [message #245144 is a reply to message #245130] Fri, 15 June 2007 05:11 Go to previous message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
So you surely found this explanation, including example.
Sorry, I cannot state it clearer.
Previous Topic: pl/sql parsing
Next Topic: TRUNC VS TO_CHAR
Goto Forum:
  


Current Time: Tue Dec 06 12:00:11 CST 2016

Total time taken to generate the page: 0.10874 seconds