Home » SQL & PL/SQL » SQL & PL/SQL » About format for TO_NUMBER
About format for TO_NUMBER [message #1175] Mon, 08 April 2002 08:15 Go to next message
sorcer
Messages: 19
Registered: January 2002
Junior Member
Hello,
I have three fields :
YEAR = '2002'
MONTH = '01'
DAY = '31'
and i want to convert it to number like this :
MY_DATE = 20020131
and i tried with :
SELECT (TO_NUMBER(YEAR, '9999') || TO_NUMBER(MONTH, '99') || TO_NUMBER(DAY, '99')) AS MY_DATE FROM DUAL
but it results :
MY_DATE = 2002311

Can somebedy help me !
Thank you very much.
Re: About format for TO_NUMBER [message #1176 is a reply to message #1175] Mon, 08 April 2002 08:46 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
WORKS FINE FOR ME!!.
didnt use dual..thats it.

SQL> DESC OO
Name Null? Type
----------------------------------------- -------- ----------------------------
Y VARCHAR2(10)
M VARCHAR2(10)
D VARCHAR2(10)

SQL> SELECT * FROM OO;

Y M D
---------- ---------- ----------
2002 01 31

SQL> SELECT (TO_NUMBER(Y, '9999') || TO_NUMBER(M, '99') || TO_NUMBER(D, '99')) MY_DATE FROM OO;

MY_DATE
--------------------------------------------------------------------------------
2002131
Re: About format for TO_NUMBER [message #1179 is a reply to message #1175] Mon, 08 April 2002 23:48 Go to previous messageGo to next message
sorcer
Messages: 19
Registered: January 2002
Junior Member
I'm waiting for :
MY_DATE = 20020131
and not
MY_DATE = 2002131
Re: About format for TO_NUMBER [message #1184 is a reply to message #1179] Tue, 09 April 2002 07:12 Go to previous messageGo to next message
Epe
Messages: 99
Registered: March 2002
Member
Hello,

why don't you multiply them ?

select to_number(year)*10000 +
to_number(month)*100 +
to_number(day)
from table;

I hope this helps,

epe
Re: About format for TO_NUMBER [message #1273 is a reply to message #1175] Tue, 16 April 2002 05:27 Go to previous message
active_amit@indiatimes.co
Messages: 1
Registered: April 2002
Junior Member
Try this one----

SELECT (YEAR||MONTH||DAY) AS MY_DATE FROM table_name

or

SELECT to_date( (YEAR||MONTH||DAY),'yyyymmdd') AS MY_DATE FROM table_name
Previous Topic: database links
Next Topic: import a file using sqlloader
Goto Forum:
  


Current Time: Thu Apr 25 18:15:43 CDT 2024