Home » SQL & PL/SQL » SQL & PL/SQL » date to number conversion (oracle 10g)
date to number conversion [message #454572] Thu, 06 May 2010 05:46 Go to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
Hi,
I want to change a table datatype from date to number where already
existing data should get convert.any possibilty of doing where i tried like this but no get changing.Even as Julian format is helping a bit i want the data to come as GMT formatl

Scenarios where i tried are like this.

ALTER TABLE Contacts ADD ALERT_DATE1 NUMBER(20,0)
/
UPDATE Contacts SET ALERT_DATE1 = TO_NUMBER(ALERT_DATE)
/
ALTER TABLE Contacts DROP COLUMN ALERT_DATE
/
ALTER TABLE Contacts RENAME COLUMN ALERT_DATE1 TO ALERT_DATE
/

but second statement failing.

Julian fomat like
SELECT sysdate,
  TO_CHAR(sysdate, 'J'),
  TO_DATE(TO_CHAR(sysdate, 'J'),'J')
FROM dual;


any suggestions will be highly appreciated.
Thanks,
Rajasekhar
Re: date to number conversion [message #454573 is a reply to message #454572] Thu, 06 May 2010 05:48 Go to previous messageGo to next message
cookiemonster
Messages: 13966
Registered: September 2008
Location: Rainy Manchester
Senior Member
How can you have GMT format in a number column?

Re: date to number conversion [message #454574 is a reply to message #454572] Thu, 06 May 2010 05:51 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
Quote:
but second statement failing.

so you already lost the data of alert_date column

sriram Smile
Re: date to number conversion [message #454576 is a reply to message #454574] Thu, 06 May 2010 05:57 Go to previous messageGo to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
Is there anyway apart from doing with Julian format?If so please let me know in doing.
Re: date to number conversion [message #454577 is a reply to message #454572] Thu, 06 May 2010 06:01 Go to previous messageGo to next message
cookiemonster
Messages: 13966
Registered: September 2008
Location: Rainy Manchester
Senior Member
Not that I can think of.
Obvious question is why do you want to use a number column at all?
Especially since you don't appear to know what you want to store in it.
Re: date to number conversion [message #454579 is a reply to message #454576] Thu, 06 May 2010 06:05 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
First reply to cookie`s question...
why number?
why not date?
new_time will convert date from one timezone to another if you want then try with that...
But dont forget reply cookie`s question..got it?

sriram Smile



Re: date to number conversion [message #454580 is a reply to message #454579] Thu, 06 May 2010 06:08 Go to previous messageGo to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
I will try accordingly to yours but the requirement came like that where i tried but it failed.so i replied here for getting any suggestions in it.Anyway i got more valuable information in this regard,

Thank you.
Re: date to number conversion [message #454581 is a reply to message #454580] Thu, 06 May 2010 06:11 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
Do you know the difference among timestamp with timezone,number,date and char.

Do you need to store the date in a number column and dispaly as GMT format ? is that your requiremnet

sriram Smile
Re: date to number conversion [message #454582 is a reply to message #454572] Thu, 06 May 2010 06:11 Go to previous messageGo to next message
cookiemonster
Messages: 13966
Registered: September 2008
Location: Rainy Manchester
Senior Member
If you want to spend lots of time fixing bugs and dodgy data then you can try storing the date as a number.
But I really strongly advise that you leave it as a date.
Re: date to number conversion [message #454583 is a reply to message #454582] Thu, 06 May 2010 06:19 Go to previous messageGo to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
yes exactly
Re: date to number conversion [message #454584 is a reply to message #454583] Thu, 06 May 2010 06:23 Go to previous message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
Then go ahead
Previous Topic: Update multiple records
Next Topic: PL/SQL
Goto Forum:
  


Current Time: Mon Apr 28 03:41:56 CDT 2025