Solved

Updating a date field in PL/SQL

Posted on 2008-10-31
3
870 Views
Last Modified: 2013-12-19
I would like to know the easiest way to update a date field in pl/sql.  I have a date field that was imported incorrectly from an .csv file into my oracle table.

The date field came in as follows:
08/24/0001 which should be 08/20/2001
09/01/0098 which should be 09/01/1998

Please help.
0
Comment
Question by:ewgf2002
3 Comments
 
LVL 10

Accepted Solution

by:
dbmullen earned 350 total points
ID: 22854946
assuming there are no rows in the future (ie.. 2009, 2010, 2011...)

update tablea
set date_column = add_months(date_column,12 * 2000)
where to_char(date_column,'yyyy') between '0000' and '0008'
;

update tablea
set date_column = add_months(date_column,12 * 1900)
where to_char(date_column,'yyyy') between '0009' and '0099'
;

commit;
0
 
LVL 9

Assisted Solution

by:jamesgu
jamesgu earned 150 total points
ID: 22855017
update a
set d = case when d > to_date('01/01/0050') then add_months(d, 1900 * 12)
else add_months(d, 2000 * 12)
end
;
--d is the column name

0
 

Author Closing Comment

by:ewgf2002
ID: 31512222
I wish to thank you both.  dbmullen's solution narrowed the results to what i needed.  both solutions will work thought.  thanks again.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now