Edi Yanto (何 萬 新)

Spell Number

Posted by: Edi Yanto on: October 28, 2008

CREATE OR REPLACE PACKAGE spell_number_pkg AS
/*
Spell Number in Indonesia and English
*/
AMOUNT_EXCEEDS_LIMIT EXCEPTION;

function to_words(
p_amount number
) return varchar2;

function spell_number(
p_number in number
) return varchar2;
END spell_number_pkg;

CREATE OR REPLACE PACKAGE BODY spell_number_pkg
IS
/*
Spell Number in Indonesia and English
*/
–*******************************************************************
–* PRIVATE MEMBERS
TYPE varchar2_tbl_t IS TABLE OF VARCHAR2 (30);

FUNCTION to_hundredth_words (p_amount NUMBER)
RETURN VARCHAR2
IS
l_translate_groups   varchar2_tbl_t
:= varchar2_tbl_t (‘SATU’,
‘DUA’,
‘TIGA’,
‘EMPAT’,
‘LIMA’,
‘ENAM’,
‘TUJUH’,
‘DELAPAN’,
‘SEMBILAN’
);
l_tenth_groups       varchar2_tbl_t
:= varchar2_tbl_t (”, ‘PULUH’, ‘RATUS’);
l_char               VARCHAR2 (3);
l_length             NUMBER;
l_number             NUMBER;
l_words              VARCHAR2 (2000);
BEGIN
l_char := TO_CHAR (p_amount);
l_length := LENGTH (l_char);

FOR i IN 1 .. l_length
LOOP
l_number := TO_NUMBER (SUBSTR (l_char, l_length + 1 – i, 1));

IF (l_number != 0)
THEN
l_words :=
l_translate_groups (l_number)
|| RTRIM (‘ ‘ || l_tenth_groups (i))
|| RTRIM (‘ ‘ || l_words);
END IF;
END LOOP;

IF (l_words IS NOT NULL)
THEN
l_words := REPLACE (l_words, ‘SATU RATUS’, ‘SERATUS’);
l_words := REPLACE (l_words, ‘SATU PULUH SATU’, ‘SEBELAS’);
l_words := REPLACE (l_words, ‘SATU PULUH’, ‘SEPULUH’);
l_words := REPLACE (l_words, ‘SEPULUH DUA’, ‘DUA BELAS’);
l_words := REPLACE (l_words, ‘SEPULUH TIGA’, ‘TIGA BELAS’);
l_words := REPLACE (l_words, ‘SEPULUH EMPAT’, ‘EMPAT BELAS’);
l_words := REPLACE (l_words, ‘SEPULUH LIMA’, ‘LIMA BELAS’);
l_words := REPLACE (l_words, ‘SEPULUH ENAM’, ‘ENAM BELAS’);
l_words := REPLACE (l_words, ‘SEPULUH TUJUH’, ‘TUJUH BELAS’);
l_words := REPLACE (l_words, ‘SEPULUH DELAPAN’, ‘DELAPAN BELAS’);
l_words := REPLACE (l_words, ‘SEPULUH SEMBILAN’, ‘SEMBILAN BELAS’);
END IF;

RETURN l_words;
END to_hundredth_words;

–**********************************************************
–* PUBLIC MEMBERS
FUNCTION to_words (p_amount NUMBER)
RETURN VARCHAR2
IS
l_thousandth_groups   varchar2_tbl_t
:= varchar2_tbl_t (”, ‘RIBU’, ‘JUTA’, ‘MILIAR’, ‘TRILIUN’);
l_idx                 NUMBER          := 1;
l_amount              NUMBER;
l_fraction            NUMBER;
l_hundredth_words     VARCHAR2 (240);
l_words               VARCHAR2 (2000);
BEGIN
l_amount := TRUNC (ABS (p_amount));

IF (LENGTH (TO_CHAR (l_amount)) > 3 * l_thousandth_groups.COUNT)
THEN
RAISE amount_exceeds_limit;
END IF;

l_fraction := ABS (ROUND (p_amount, 2)) – l_amount;

LOOP
l_hundredth_words :=
to_hundredth_words (l_amount – TRUNC (l_amount, -3));

IF (l_hundredth_words IS NOT NULL)
THEN
l_words :=
l_hundredth_words
|| RTRIM (‘ ‘ || l_thousandth_groups (l_idx))
|| RTRIM (‘ ‘ || l_words);
END IF;

l_amount := TRUNC (l_amount, -3) / 1000;
EXIT WHEN l_amount = 0;
l_idx := l_idx + 1;
END LOOP;

IF (SUBSTR (l_words, 1, 9) = ‘SATU RIBU’)
THEN
l_words := ‘SERIBU’ || SUBSTR (l_words, 10);
END IF;

l_words := l_words;

IF (l_fraction != 0)
THEN
l_words :=
l_words || ‘ ‘ || to_hundredth_words (l_fraction * 100)
|| ‘ SEN’;
END IF;

RETURN l_words;
END to_words;

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 (TO_NUMBER (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 spell_number;
END spell_number_pkg;
/

Leave a Reply

RSS Syndication


Edi Yanto
Oracle Applications Technical Consultant
View Edi Yanto's profile on LinkedIn
Edi Yanto (何 萬 新) - Blogged Page Rank Check

My Certifications

RSS Edi Yanto (何万新)

  • Oracle Top-N Query October 2, 2009
    Using RANK function, with a faster execution plan (WINDOW SORT PUSHED RANK) SELECT Empno, Ename, Job, Mgr, Hiredate, Sal FROM (SELECT Empno, Ename, Job, Mgr, Hiredate, Sal, RANK() OVER (ORDER BY SAL Desc) AS Emp_Rank FROM Emp) WHERE Emp_Rank
    Edi Yanto
  • Bersyukurlah… June 30, 2009
    AKU TAK SELALU MENDAPATKAN APA YANG KUSUKAI oleh karena itu AKU SELALU MENYUKAI APAPUN YANG AKU DAPATKAN. Kata-kata di atas merupakan wujud syukur. Syukur merupakan kualitas hati yang terpenting. Dengan bersyukur kita akan senantiasa diliputi rasa damai, tentram dan bahagia. Sebaliknya, perasaan tak bersyukur akan senantiasa membebani kita. Kita akan selalu […]
    Edi Yanto
  • Cinta Sejati June 30, 2009
    Kenapa kita menutup mata ketika kita tidur ? Kenapa kita menutup mata ketika kita menangis ? Kenapa kita menutup mata ketika kita membayangkan sesuatu ? Kenapa kita menutup mata ketika kita berciuman ? Hal hal yang terindah di dunia ini biasanya tidak terlihat Ada hal hal yang tidak ingin kita lepaskan dan ada orang orang yang tidak ingin kita tinggalkan Tap […]
    Edi Yanto
  • Nice Story June 8, 2009
    Share on Facebook
    Edi Yanto
  • 5 Tips Agar Tak Mudah Lelah June 2, 2009
    Sebagian orang mengeluhkan kondisi tubuhnya yang cepat capai atau lelah. Kebanyakan orang menilai hal itu diakibatkan kerja ekstra. Tetapi, sebenarnya hal itu dilatarbelakangi kebiasaan seseorang sehari-hari. Berikut lima tips yang dikutip VIVAnews dari WebMD, Sabtu 25 April 2009 agar kondisi tubuh Anda tidak mudah capai atau lelah. 1. Lapar atau tidak, sara […]
    Edi Yanto
  • Belajar dari Alphabet May 29, 2009
    A : AcceptTerimalah diri anda sebagaimana adanya. B : BelievePercayalah terhadap kemampuan anda untuk meraih apa yang anda inginkan dalam hidup. C : CarePedulilah pada kemampuan anda meraih apa yang anda inginkan dalam hidup. D : DirectArahkan pikiran pada hal-hal positif yang meningkatkan kepercayaan diri. E : EarnTerimalah penghargaan yang diberi orang lai […]
    Edi Yanto
  • How To Get the List of All Responsibilities Assigned To A User May 29, 2009
    Edi Yanto
  • Query To Find Multi-Org Is Enabled Or Not May 29, 2009
    SELECT DECODE (multi_org_flag, ‘Y’, ‘Multi-Org Enabled’, ‘Multi-Org Disabled’ ) FROM fnd_product_groups; Share on Facebook
    Edi Yanto
  • How To Find A Patch Is Applied For A Bug May 29, 2009
    Edi Yanto
  • Excel Limitations on Images in Oracle Apps May 23, 2009
    The Excel output can’t showing the image (even after you save and send to another person or open it at different notebook), but it is showing only small red color empty cross written ‘An Image’.  Why??? As many of you know or have noticed, our Excel output for all flavors of BIP/XMLP is not true binary [...]
    Edi Yanto

 

October 2008
M T W T F S S
« Sep   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Visitors

Blog Stats

  • 28,328 hits

Users Online

web counter

Pages