Monday, March 10, 2008

Converting Number to Text using Oracle SQL Explained

Query:
select to_char(to_date('456','J'),'Jsp') --replace 456 with your number or variablefrom dual
Output:
Four Hundred Fifty-Six

How it works:
Step 1:

Following query will convert your number to date format. As this is number we need to specify 'J'ulian format.

Query:
select to_date('456','J') --replace 456 with your number or variablefrom emp
Output:
01-APR-11

Step 2:
Following query will convert your number (date in 'J'ulian format) to text. If you write 'sp' after any format, the format will be spelled. So the number 456 will be converted to text as "Four Hundred Fifty-Six "

Query:
select to_char(to_date('456','J'),'Jsp') --replace 456 with your number or variablefrom dual
Output:
Four Hundred Fifty-Six

No comments: