Created
August 6, 2014 09:05
-
-
Save octavian-nita/fc746d523fd45fb5f327 to your computer and use it in GitHub Desktop.
Spelling numbers in PL/SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 (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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment