Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

RE: NUMBER TO LETTERS CONVERTER

FUNCTION
Posted by Micky Master on 3/5/2007 8:20:00 AM
Hi
Try Below Two functions as per your requirement.
(1).........................
1* SELECT to_char(date '-4712-01-01' + (&n-1), 'JSP') from dual
Enter value for n: 1721058
old 1: SELECT to_char(date '-4712-01-01' + (&n-1), 'JSP') from dual
new 1: SELECT to_char(date '-4712-01-01' + (1721058-1), 'JSP') from dual
TO_CHAR(DATE'-4712-01-01'+(1721058-1),'JSP')
--------------------------------------------------------ONE MILLION SEVEN HUNDRED TWENTY-ONE THOUSAND FIFTY-EIG
(2)..........................................
create or replace
2 function spell_number( p_number in number )
3 return varchar2
4 as
5
type myArray is table of varchar2(255);
6
l_str myArray := myArray( '',
7
' thousand ', ' million ',
8
' billion ', ' trillion ',
9
' quadrillion ', ' quintillion ',
10
' sextillion ', ' septillion ',
11
' octillion ', ' nonillion ',
12
' decillion ', ' undecillion ',
13
' duodecillion ' );
14
15
l_num varchar2(50) default trunc( p_number );
16
l_return varchar2(4000);
17 begin
18
for i in 1 .. l_str.count
19
loop
20
exit when l_num is null;
21
22
if ( substr(l_num, length(l_num)-2, 3) <> 0 )
23
then
24
l_return := to_char(
25
to_date(
26
substr(l_num, length(l_num)-2, 3),
27
'J' ),
28
'Jsp' ) || l_str(i) || l_return;
29
end if;
30
l_num := substr( l_num, 1, length(l_num)-3 );
31
end loop;
32

33
return l_return;
34 end;
35 /
Function created.
ops$tkyte@DEV816>
ops$tkyte@DEV816> select
2 spell_number( 12345678901234567890123456789012345678 )
3 from dual;
SPELL_NUMBER(1234567890123456789012345678901234567
-------------------------------------------------Twelve undecillion Three Hundred Forty-Five decill
ion Six Hundred Seventy-Eight nonillion Nine Hundr
ed One octillion Two Hundred Thirty-Four septillio
n Five Hundred Sixty-Seven sextillion Eight Hundre
d Ninety quintillion One Hundred Twenty-Three quad
rillion Four Hundred Fifty-Six trillion Seven Hund
red Eighty-Nine billion Twelve million Three Hundr
ed Forty-Five thousand Six Hundred Seventy-Eight
----------------------------------------------------------------------------------------------------------------

Regards
Tariq Bashir
Cell + 966 - 502652230

Re: NUMBER TO LETTERS CONVERTER


FUNCTION
Posted by ahmadnoman on 3/6/2007 12:32:00 AM

function convert_number (value number) return varchar2 is


value_text varchar2(80);
begin
value_text := to_char( to_date(value,'YYYY'),'Yyyysp');
return(value_text);
end;
On 3/5/07, joshhhhhh via oracle-dev-l

Re: NUMBER TO LETTERS CONVERTER

FUNCTION
Posted by SQLUSA on 3/6/2007 6:26:00 AM
> function convert_number (value number) return varchar2 is
> value_text varchar2(80);
> begin
> value_text := to_char( to_date(value,'YYYY'),'Yyyysp');
> return(value_text);
> end;
>
Performance-wise, how the function solution compares to inline script?
Kalman Toth - Database, Data Warehouse & Business Intelligence Architect
SQLUSA: http://www.sqlusa.com/order2005crashcourse/ The Best SQL Server
2005 Training in the World
----- Original Message ----From: "ahmadnoman via oracle-dev-l" <email@removed>
To: "SQLUSA" <email@removed>
Sent: Tuesday, March 06, 2007 1:27 AM
Subject: Re: [oracle-dev-l] NUMBER TO LETTERS CONVERTER FUNCTION
>
> function convert_number (value number) return varchar2 is
> value_text varchar2(80);
> begin
> value_text := to_char( to_date(value,'YYYY'),'Yyyysp');
> return(value_text);
> end;
>
>
>
>
> On 3/5/07, joshhhhhh via oracle-dev-l
> wrote:
>>
>>
>>
> > Try This
> > select to_char(to_date( 9341 ,'J' ), 'JSP' ) from dual; cheers vinod
> > -----"afahed via oracle-dev-l" x.com> wrote: ----- To: joshhhhhh From:
"afa
> > hed via oracle-dev-l" Date: 03
> > /05/2007 01:13PM Subject: RE: [oracle-dev-l] NUMBER TO LETTERS CONVERTER
> > FUNCTION Thanks a lot for your help but
> > I want the converter to convert the number to letters like If I put
> > 4320 the out put will be four thousands three hundred twenty Or some t
> > hing like that Thanks and I appreciate your help Regards Fahed A
> > hmad -----Original Message----- From: meetasher via oracle-dev-l
> > [ mailt
> > o:<email@removed> ] Sent: 5/Mar/2007 3:45 PM To
> > : Fahed Ahmed Subject: Re: [oracle-dev-l] NUMBER TO LETTERS CONVERTER FU

> > NCTION HI CHECK IT OUT... SQL> SELECT CHR(6


> > 5) FROM DUAL; C- ATHANKS AND REGARDS ----> > Original Message ----- From: "afahed via oracle-dev-l"
@Groups.ITtoolbox.com> To: "meetasher" Sent:
> > Monday, March 05, 2007 5:28 PM Subject: [oracle-dev-l] NUMBER T
> > O LETTERS CONVERTER FUNCTION > > > DEAR All;
> > > I have a form that takes trhe numbers and I want ot transfer the nu
> > mber > into the letters I know this function but the problem is that
> > I forgot > it > Can anybody help? > Your help is apprecia
> > ted > Regards > Fahed Ahmad > "Disclaimer: The informatio
> > n in this email and in any files transmitted with it is intended only
> > for the addressee and may contain confidential and/or privileged materi
> > al. Access to this email by anyone else is unauthorized. If you receive
> > this in error, please contact the sender immediately and delete the mate
> > rial from any computer. If you are not the intended recipient, any di
> > sclosure, copying, distribution or any action taken or omitted to be tak
> > en in reliance on it, is strictly prohibited. Al-Rabie is a food manufac
> > turing and distribution company; Proper verification is necessary before
> > any actions could be taken based on the contents of this e-mail; Statem
> > ents and opinions expressed in this e-mail are those of the sender, a
> > nd do not necessarily reflect those of Al-Rabie." > > &g
> > t; > > > > "Disc
> > laimer: The information in this email and in any files transmitted with
it
> > is intended only for the addressee and may contain confidential and/or
> > priv
> > ileged material. Access to this email by anyone else is unauthorized. If
> > yo
> > u receive this in error, please contact the sender immediately and
delete
>>t
> > he material from any computer. If you are not the intended recipient,
any
>>d
> > isclosure, copying, distribution or any action taken or omitted to be
> > taken
> > in reliance on it, is strictly prohibited. Al-Rabie is a food
manufacturin
> > g and distribution company; Proper verification is necessary before any
> > act
> > ions could be taken based on the contents of this e-mail; Statements and
> > op
> > inions expressed in this e-mail are those of the sender, and do not
> > necessa
> > rily reflect those of Al-Rabie."
>>
>>
All i
> > nformation in this communication, including attachments, is strictl
> > y confidential and intended solely for delivery to and authorized use by
> > th
> > e addresses(s) identified above, and may contain privileged, confid
> > ential, proprietary and/or trade secret information entitled to protect
> > ion and/or exempt from disclosure under applicable law. If you are not
> > the
> > intended recipient, please take notice that any use, distribution
> > or copying of this communication, and/or any action taken or omitted to

> > be taken in reliance upon it, is unauthorized and may be unlawful. If
> > you have received this communication in error, please notify the sende
> > r and delete this communication from your computer.
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>

RE: NUMBER TO LETTERS CONVERTER


FUNCTION
Posted by George Lewycky on 3/6/2007 4:49:00 PM
If you have Oracle's Financial APPS:
AP_AMOUNT_UTILITIES_PKG is a canned package that has this capability:
Here is the PL/SQL, plus I included another one I found on the web
beneath this...
George Lewycky
http://georgenet.net/oracle
CREATE OR REPLACE PACKAGE AP_AMOUNT_UTILITIES_PKG AUTHID CURRENT_USER
AS
/* $Header: apamtuts.pls 115.1 99/09/30 16:00:38 porting ship $ */
FUNCTION ap_convert_number(in_numeral IN NUMBER) RETURN VARCHAR2;
END AP_AMOUNT_UTILITIES_PKG;
/

CREATE OR REPLACE PACKAGE BODY AP_AMOUNT_UTILITIES_PKG AS


/* $Header: apamtutb.pls 115.4 99/09/02 16:01:56 porting s $ */
function ap_convert_number (in_numeral IN NUMBER) return varchar2 is
c_zero
ap_lookup_codes.displayed_field%TYPE;
c_thousand
ap_lookup_codes.displayed_field%TYPE;
c_million
ap_lookup_codes.displayed_field%TYPE;
c_billion
ap_lookup_codes.displayed_field%TYPE;
number_too_large exception;
numeral
integer := abs(in_numeral);

max_digit
integer := 12; -- for numbers less than a
trillion
number_text
varchar2(240) := '';
billion_seg
varchar2(25);
million_seg
varchar2(25);
thousand_seg
varchar2(25);
units_seg
varchar2(25);
billion_lookup
varchar2(80);
million_lookup
varchar2(80);
thousand_lookup varchar2(80);
units_lookup
varchar2(80);
session_language fnd_languages.nls_language%TYPE;
thousand
number
:= power(10,3);
million
number
:= power(10,6);
billion
number
:= power(10,9);
begin
if numeral >= power(10,max_digit) then
raise number_too_large;
end if;
--For Bug459665
if numeral = 0 then
select ' '||displayed_field||' '
into
c_zero
from ap_lookup_codes
where lookup_code = 'ZERO';
return(c_zero);
end if;
billion_seg := to_char(trunc(numeral/billion));
numeral := numeral - (trunc(numeral/billion) * billion);
million_seg := to_char(trunc(numeral/million));
numeral := numeral - (trunc(numeral/million) * million);
thousand_seg := to_char(trunc(numeral/thousand));
units_seg := to_char(mod(numeral,thousand));
select ' '||lc1.displayed_field||' ',
' '||lc2.displayed_field||' ',
' '||lc3.displayed_field||' ',
' '||lc4.displayed_field,
lc5.description,
lc6.description,
lc7.description,
lc8.description
into c_billion,
c_million,
c_thousand,
c_zero,
billion_lookup,
million_lookup,
thousand_lookup,
units_lookup
from ap_lookup_codes lc1,
ap_lookup_codes lc2,

ap_lookup_codes lc3,
ap_lookup_codes lc4,
ap_lookup_codes lc5,
ap_lookup_codes lc6,
ap_lookup_codes lc7,
ap_lookup_codes lc8
where lc1.lookup_code = 'BILLION'
and lc1.lookup_type = 'NLS TRANSLATION'
and lc2.lookup_code = 'MILLION'
and lc2.lookup_type = 'NLS TRANSLATION'
and lc3.lookup_code = 'THOUSAND'
and lc3.lookup_type = 'NLS TRANSLATION'
and lc4.lookup_code = 'ZERO'
and lc4.lookup_type = 'NLS TRANSLATION'
and lc5.lookup_code = billion_seg
and lc5.lookup_type = 'NUMBERS'
and lc6.lookup_code = million_seg
and lc6.lookup_type = 'NUMBERS'
and lc7.lookup_code = thousand_seg
and lc7.lookup_type = 'NUMBERS'
and lc8.lookup_code = units_seg
and lc8.lookup_type = 'NUMBERS';
--Commented For Bug459665
/*
if numeral = 0 then
return(c_zero);
end if;
*/
select substr(userenv('LANGUAGE'),1,instr(userenv('LANGUAGE'),'_')-1)
into session_language
from dual;
--Bug 335063 fix.
if (session_language = 'FRENCH' or session_language = 'CANADIAN
FRENCH')
and thousand_seg = '1' then
thousand_lookup := null;
end if;
-if billion_seg <> '0' then
number_text := number_text||billion_lookup ||c_billion;
end if;
if million_seg <> '0' then
number_text := number_text||million_lookup||c_million;
end if;
if thousand_seg <> '0' then
number_text := number_text||thousand_lookup||c_thousand;
end if;
if units_seg <> '0' then
number_text := number_text||units_lookup;

end if;
number_text := ltrim(number_text);
number_text := upper(substr(number_text,1,1)) ||
rtrim(lower(substr(number_text,2,length(number_text))));
return(number_text);
exception
when number_too_large then
return(null);
when others then
return(null);
end;
END AP_AMOUNT_UTILITIES_PKG;
/

And I FOUND THIS ONE A FEW YEARS AGO ON THE WEB:


http://www.geocities.com/oracletricks/plsql/currencywords.txt
--

-- Copywright 2002, joel crainshaw & chet west


--

-- DESCRIPTION
-- convert a number to words for printinng checks
-- there are numerous solutions and this one was pulled together
-- from several other solutions we found; unfortunately, we don't
have
-- the original author out function is baased on to provide credit
--- this is the "limited" solution that usses julian date conversions
-- to simply accomplish the results whichh limits our output to
-- $5,373,484.00
--

-- MODIFICATION HISTORY
-- Person
Date
Comments
-- --------- ---------- --------------------------------------------- chet/joel ??/??/2001 Initial Creation

--

CREATE OR REPLACE FUNCTION currencywords (


p_val IN NUMBER
)
RETURN CHAR IS
cents NUMBER;
c_str VARCHAR2 (80);
FUNCTION spell (
p_value IN NUMBER
)
RETURN CHAR IS
BEGIN
IF p_value > 0 THEN
RETURN (INITCAP (TO_CHAR (TO_DATE (p_value, 'j'), 'jsp')));
ELSE
RETURN ('');
END IF;
END spell;
-BEGIN
cents := MOD (p_val, 1) * 100;
IF cents > 0 THEN -- creates string for cents
c_str := ' dollars AND ' || LOWER (spell (cents)) || ' cents';
ELSE
c_str := ' dollars AND zero cents';
END IF;
IF

p_val >= 1
AND p_val <= 5373484 THEN -- creates dollar string up to
$5,373,484.00
RETURN ('** the SUM OF '|| INITCAP (spell (FLOOR (p_val))) ||
c_str || '**');
ELSE
RETURN ('** error **');
END IF;
END; -- Function CURRENCYWORDS

You might also like