Académique Documents
Professionnel Documents
Culture Documents
FUNCTION
Posted by Micky Master on 3/5/2007 8:20:00 AM
Hi
(1).........................
(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
>
> 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.
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>
Here is the PL/SQL, plus I included another one I found on the web
beneath this...
George Lewycky
http://georgenet.net/oracle
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));
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;
/
--
-- 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
--
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 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