Home » Developer & Programmer » Reports & Discoverer » spell out the numbers into words.
spell out the numbers into words. [message #89471] Mon, 12 April 2004 08:13 Go to next message
shah hasan
Messages: 1
Registered: April 2004
Junior Member
dear all.
pls help me . i have a summary column formula which is contain the numeric value. i want to a function, or query which return the any value in the summary column would be autometically speelld out. wold it is possible..
thx for help

example:------
summary column name cs-1
datatype number
elength 36
input data 187,654,33
i want the input data to be spelled out tha xfor hewlp
Re: spell out the numbers into words. [message #89476 is a reply to message #89471] Thu, 15 April 2004 01:48 Go to previous messageGo to next message
Riaz
Messages: 112
Registered: February 2002
Senior Member
Converting Numbers to Words.  (Type: SQL*Plus) 
There is a little-known method in SQL to easily 
convert a number to it's word equivalent (i.e. 
convert 123 to "One Hundred Twenty-Three").  This 
method is very easy to use and requires no PL/SQL 
coding! 
SQL To Convert Number to Words 
Here is the SQL that can be used to spell out a 
number: 
SQL> SELECT TO_CHAR(TO_DATE(12345, 'J'), 'JSP') FROM 
DUAL 
  2  / 
 
TO_CHAR(TO_DATE(12345,'J'),'JSP') 
---------------------------------------- 
TWELVE THOUSAND THREE HUNDRED FORTY-FIVE 
How does this work? 
Special TO_CHAR Date Format: JSP  
There is a special TO_CHAR date format named "JSP" 
that takes a julian date and spells out it's number 
(JSP=Julian SPelled out).  This conversion can be 
used to spell out any number.  For example, the 
following query 
SQL> SELECT sysdate, TO_CHAR(sysdate, 'J') FROM DUAL 
  2  / 
 
SYSDATE   TO_CHAR 
--------- ------- 
09-MAR-02 2452343 
The number 2452343 is the julian date for 09-MAR-02.  
Now let's try the JSP format: 
SQL> SELECT TO_CHAR(sysdate, 'JSP') FROM DUAL 
  2  / 
 
TO_CHAR(SYSDATE,'JSP') 
------------------------------------------------------------------------ 
TWO MILLION FOUR HUNDRED FIFTY-TWO THOUSAND THREE 
HUNDRED FORTY-THREE 
This is same julian number for 09-MAR-02, but spelled 
out.  
Convert Number to Date then use JSP 
Now if we take a number and convert it to a date 
using the "J" format in TO_DATE, then convert it back 
to a character string using the "JSP" format in 
TO_CHAR, we get the result we want: 
SQL> SELECT TO_CHAR(TO_DATE(12345, 'J'), 'JSP') FROM 
DUAL 
  2  / 
 
TO_CHAR(TO_DATE(12345,'J'),'JSP') 
---------------------------------------- 
TWELVE THOUSAND THREE HUNDRED FORTY-FIVE 

Re: spell out the numbers into words. [message #89479 is a reply to message #89476] Thu, 15 April 2004 04:01 Go to previous messageGo to next message
Hasan Imam
Messages: 13
Registered: April 2004
Junior Member
But there is proplem when arise fraction or avobe 7 digit
Re: spell out the numbers into words. [message #89499 is a reply to message #89479] Sun, 25 April 2004 21:54 Go to previous message
Riaz
Messages: 112
Registered: February 2002
Senior Member
CREATE OR REPLACE FUNCTION NUMBER_CONVERSION(NUM NUMBER) RETURN VARCHAR2
IS
  A VARCHAR2(1000);
  B VARCHAR2(20);
  X NUMBER;
  Y NUMBER := 1;
  Z NUMBER;
  LSIGN NUMBER;
  NO NUMBER;
BEGIN
  X:= INSTR(NUM, '.');
  LSIGN := SIGN(NUM);
  NO := ABS(NUM);	
  IF X = 0 THEN 
     SELECT 	TO_CHAR(TO_DATE(NO, 'J'), 'JSP')  INTO A FROM DUAL;
  ELSE
     SELECT 	to_char(to_date(SUBSTR(NO, 1,
     		NVL(INSTR(NO, '.')-1, LENGTH(NO))),
     			'J'), 'JSP') INTO A FROM DUAL;
     SELECT	LENGTH(SUBSTR(NO, INSTR(NO, '.')+1)) INTO Z FROM DUAL;
     A := A ||' POINT ';
     WHILE Y< Z+1 LOOP
	 SELECT TO_CHAR(TO_DATE(SUBSTR(NO, (INSTR(NO, '.')+Y), 1), 'J'), 'JSP')
	       INTO B FROM DUAL;
		A := A || B ||' ';
		y :=y+1;
     END LOOP;
  END IF;
  IF LSIGN = -1 THEN
     RETURN 'NEGATIVE '||A;
  ELSE
     RETURN A;
  END IF;
END;
/
show errors

-- Examples:
Select number_conversion(-3786.9899876) from dual;
Select number_conversion(7685.78788) from dual;
Select number_conversion(7678) from dual;

Previous Topic: parameter form
Next Topic: report builder
Goto Forum:
  


Current Time: Mon Apr 29 16:08:25 CDT 2024