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: Daniel Fink <Daniel.Fink_at_Sun.COM>
Date: Tue, 23 Mar 2004 14:38:49 -0700
Message-id: <4060AE68.DB7556AF@sun.com>


Barb,

First, math on dates (add/subtract) is in days, not years. So if you use days, you also have to figure out the number of leap days in the interval. YUCK!
Second, while dates are stored as numbers, they are displayed as character strings.

So, why not just convert the character string then store it back?

Here is a q&d d&p from my own db.

TO_CHAR(INSERT_DATE


2004/03/22:10:55:54
2004/03/22:10:55:55
2004/03/22:10:55:59
2004/03/22:10:56:00
2004/03/22:10:56:01
2004/03/22:10:56:02
2004/03/22:10:56:03
2004/03/22:10:56:04
2004/03/22:10:56:05
2004/03/22:10:56:06
2004/03/22:10:56:07
2004/03/22:10:56:08
2004/03/22:10:56:09
2004/03/22:10:56:10
2004/03/22:10:56:11
2004/03/22:10:56:12
2004/03/22:10:56:13
2004/03/22:10:56:14
2004/03/22:10:56:15
2004/03/22:10:56:16
2004/03/22:10:56:17


update test_data
set insert_date = to_date('1994'||to_char(insert_date, 'MMDDhh24miss'), 'YYYYMMDDhh24miss')
/

TO_CHAR(INSERT_DATE


1994/03/22:10:55:54
1994/03/22:10:55:55
1994/03/22:10:55:59
1994/03/22:10:56:00
1994/03/22:10:56:01
1994/03/22:10:56:02
1994/03/22:10:56:03
1994/03/22:10:56:04
1994/03/22:10:56:05
1994/03/22:10:56:06
1994/03/22:10:56:07
1994/03/22:10:56:08
1994/03/22:10:56:09
1994/03/22:10:56:10
1994/03/22:10:56:11
1994/03/22:10:56:12
1994/03/22:10:56:13
1994/03/22:10:56:14
1994/03/22:10:56:15
1994/03/22:10:56:16
1994/03/22:10:56:17

You can buy me a round of scotch at Pint's Pub...

Dan

Barbara Baker wrote:

> 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
> -----------------------------------------------------------------



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 - 17:38:18 CST

Original text of this message

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