Sql oracle update date
My table table1
has a column date_txt
that includes 2/16/2011 12:00:00 AM
- column date_txt
is VARCHAR2 (250 Char)
.
My table table1
also has a column date
that is date
.
I would like to "update" my field:
The end result should be:
table1:
date
2/16/2011
So from table1
date_txt
"date" is required and update it to column date
as date.
Any ideas? I'm a bloody beginner.
source to share
You can use Oracle to_date function to convert string to date:
update table1 set "date" = to_date(date_txt, 'MM/DD/YYYY HH:MI:ss AM')
source to share
column date_txt which includes 2/16/2011 12:00:00 AM
-
First, DATE has no format... What you see is for display to easily interpret the date value.
-
Second, you should never store DATE as VARCHAR2 . This is a big problem and bad design.
Now that you have a bad design, it's a good idea to fix it right now.
Follow these steps:
- Add a new column with data type DATE .
- Update the new column with the date values ββfrom the old column using TO_DATE .
- Drop the old column.
- Rename the new column to the old column.
I already answered how to do it here fooobar.com/questions/2216183 / ...
source to share