DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Number to word function

  1. #1
    Join Date
    May 2001
    Posts
    4
    Can anyone help me? Is there any function or packaged procedure that can convert the number to words.

    Thanks

    Joyal

  2. #2
    Join Date
    Feb 2001
    Location
    Bombay,India
    Posts
    530
    Hi,
    There is no function or package pocedure that can convert the number to words.U have to draft ur own procedure or function to do it.

    Regards,
    Rohit Nirkhe,oracle DBA,OCP 8i
    [email protected]

  3. #3
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    There is an old trick for converting numbers to english words by using special format of Julian dates. Example:

    SQL> SELECT TO_CHAR( TO_DATE( 1234567, 'J'),' JSP') FROM dual;

    TO_CHAR(TO_DATE(1234567,'J'),'JSP')
    ---------------------------------------------------------------------
    ONE MILLION TWO HUNDRED THIRTY-FOUR THOUSAND FIVE HUNDRED SIXTY-SEVEN

    SQL>

    You are limited to up-to 7 digits ******* values in the range that Julian dates can handle, but with some inventive combining of functions you could even surpass those limits. BTW, format picture 'J' stands for Julian date conversion (date to number), while 'JSP' stands for Julian dates SPelled.

    HTH,
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  4. #4
    Join Date
    May 2001
    Posts
    4

    Smile

    Thanks a mio

  5. #5
    Join Date
    Feb 2001
    Location
    Kolkata- India
    Posts
    356

    Cool

    Here, I got this from someone,


    create or replace
    function spell_number( p_number in number )
    return varchar2
    as
    type myArray is table of varchar2(255);
    check_number number;
    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;
    SELECT to_number(substr(l_num, length(l_num)-2, 3))
    INTO check_number
    FROM dual;
    IF check_number > 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 );
    dbms_output.put_line(‘return value’||’ ‘||l_return);
    dbms_output.put_line(‘num value’||’ ‘||l_num);
    end loop;
    return l_return;
    end;
    /
    There Nothing You cannot Do, The problem is HOW.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width