Professional Documents
Culture Documents
Convesion Functions
Convesion Functions
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
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
> > 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.
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>
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;
/
-- 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
--
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