Solved

Updating a date field in PL/SQL

Posted on 2008-10-31
3
872 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

867 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

22 Experts available now in Live!

Get 1:1 Help Now