Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: update year in date column

RE: update year in date column

From: Riyaj Shamsudeen <rshamsud_at_jcpenney.com>
Date: Tue, 23 Mar 2004 15:35:24 -0600
Message-id: <008401c4111e$c024ba20$212f200a@rshamsudxp>


Will this do ?
Alter session set nls_date_format='DD-MON-CYYYY-HH24:MI:SS'; select * from mytabdate;

    CUSTNO CRDATE

---------- ---------------------
         1 16-SEP- 2099 00:00:00
         1 08-OCT- 2099 00:00:00

update mytabdate
set crdate =

to_date(to_char(crdate, 'DD-MON-')||
to_char(to_number(to_char(crdate,'yyyy'))-100) ||
to_char(crdate, ' HH24:MI:SS') ,'DD-MON-YYYY HH24:MI:SS')
/

2 rows updated.

 select * from mytabdate;

    CUSTNO CRDATE

---------- ---------------------
         1 16-SEP- 1999 00:00:00
         1 08-OCT- 1999 00:00:00

Thanks
Riyaj "Re-yas" Shamsudeen
Certified Oracle DBA

-----Original Message-----
From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Barbara Baker Sent: Tuesday, March 23, 2004 2:01 PM
To: oracle-l_at_freelists.org
Subject: update year in date column

OK, I'm just going to bite the bullet and claim total ignorance here and see if someone takes pity on me :(
(sad face a nice touch, eh?)

Someone has accidently updated 378 records in the customer table. The date changed from 1999 to 2099. I need to change just the year back to 1999 for these records. (I'd like to keep the time stamp, if possible. The month and day are correct.) I looked on metalink, google, and asktom. Some nice examples, but not what I really need.

Thought I'd be clever and subtract 1000 from the date. This works, but I don't know how to get it formatted back into a date.

I'd prefer just sqlplus, but will use pl/sql if necessary.

Here's what I've done so far:
(solaris 9 oracle 9.2.0.4)

JServer Release 9.2.0.4.0 - Production

DOC> CUSNO CUSNAME CRDATE

DOC>---------- -----------------------------------
----------
DOC>    798489 GILBERT, ROSS                      
09/16/2099
DOC>    826744 HOEFLER, MATT                      
10/08/2099
DOC>    795126 FORT,  JOETTA                      
09/08/2099
DOC>*/ SQL>
SQL> ---select to_date(to_char(crdate,'MM/DD/YYYY')) from customer where cusno=798489;
SQL> ---update advdb.custtest_barb
SQL>  ---set crdate= to_char(crdate,'MM/DD/YYYY'))
SQL> ---from customer where cusno=798489;
SQL> 
SQL> select
to_date(to_char(crdate,'ddmmyyyy')-1000),'MM/DD/YYYY')
  2     from customer where cusno=798489;
select
to_date(to_char(crdate,'ddmmyyyy')-1000),'MM/DD/YYYY')
                                                      
     *

ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SQL> 
SQL> 
SQL> --- these both work
SQL> select to_char(crdate,'ddmmyyyy')  from
custtest_barb where cusno=798489;

TO_CHAR(



16092099

SQL> select to_char(crdate,'ddmmyyyy') - 1000 from custtest_barb where cusno=798489;

TO_CHAR(CRDATE,'DDMMYYYY')-1000


                       16091099

Thank for any assistance.

Barb



Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html

Please see the official ORACLE-L FAQ: http://www.orafaq.com

To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------



The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If the reader of this message is not the intended recipient, you are hereby notified that your access is unauthorized, and any review, dissemination, distribution or copying of this message including any attachments is strictly prohibited. If you are not the intended recipient, please contact the sender and delete the material from any computer. ---------------------------------------------------------------- Please see the official ORACLE-L FAQ: http://www.orafaq.com ---------------------------------------------------------------- To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line. -- Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html -----------------------------------------------------------------

Received on Tue Mar 23 2004 - 16:52:54 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US