Home » SQL & PL/SQL » SQL & PL/SQL » Update to_char(date,'YYYY') (oracle 10g)
Update to_char(date,'YYYY') [message #640286] Sun, 26 July 2015 23:03 Go to next message
nciteamo
Messages: 27
Registered: October 2014
Junior Member
Hello Guys

i wanna update my table with this query below

update mytable
set to_char(NXTPAYDT,'YYYY') = '2018'


but it comes up an error message "ORA-00927: missing equal sign"

whats the problem? Syntax error?

may you guys help me?


Thanks in advance

Re: Update to_char(date,'YYYY') [message #640287 is a reply to message #640286] Sun, 26 July 2015 23:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read

What is expected/desired results?
Why do you want to change EVERY row in this table?
Re: Update to_char(date,'YYYY') [message #640289 is a reply to message #640286] Sun, 26 July 2015 23:34 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
Maybe syntax error too, but based on the logical nonsense. TO_CHAR( <column_name>, '2018' ) is not stored in the table, so it is impossible to directly change it. You can update the column itself, it is on you to give it proper value and it is not hard to compute it.

With a little help of simple math, something like this could (assuming that you want to keep month/day/hour/minute and second of that column):
update mytable
set NXTPAYDT = date '2018-01-01' + ( NXTPAYDT - trunc( NXTPAYDT, 'YYYY' ) );

(although I also fail to reason for this; maybe some data with year 18 are present in the table due to two digit year representation and wrong conversion steps)
Re: Update to_char(date,'YYYY') [message #640299 is a reply to message #640289] Mon, 27 July 2015 02:06 Go to previous message
nciteamo
Messages: 27
Registered: October 2014
Junior Member
flyboy
Thanks it works Smile
Previous Topic: Split column to rows in Oracle Sql
Next Topic: query taking lot of time to execute
Goto Forum:
  


Current Time: Wed Apr 24 18:48:23 CDT 2024