Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update only date on datetime field on Pl/SQL

Tags:

sql

oracle

plsql

So i need to update some dates on an Oracle Database, the field is a datetime, but i only want the date updated and leave the time as it is... There query goes like this:

update table 
   SET field = to_date('07312010','MMDDYY');

But it's overriding the hours, minutes and seconds from the field, i want to update the date but i want the hour to be left the same, any thoughts?

like image 581
Gotjosh Avatar asked Aug 04 '10 19:08

Gotjosh


People also ask

How do I change the value of a date column in Oracle?

Try this: update table_name set date_field = to_date('2009/05/11','yyyy/mm/dd') ; Hope this helps.

How do I change the date format in PL SQL?

Finally, you can change the default DATE format of Oracle from "DD-MON-YY" to something you like by issuing the following command in sqlplus: alter session set NLS_DATE_FORMAT='<my_format>'; The change is only valid for the current sqlplus session.

How do I update a column in Sysdate?

To display the date column, simply use TO_CHAR along with proper FORMAT MODEL. UPDATE Regarding dynamic SQL. 'UPDATE XX_TABLE last_update_date = ''' || SYSDATE || ''', WHERE 1=1';


1 Answers

You could use:

UPDATE TABLE
   SET field = TO_DATE('07312010' || ' ' || TO_CHAR(field, 'HH24:MI:SS'),
                       'MMDDYY HH24:MI:SS');
like image 59
OMG Ponies Avatar answered Sep 23 '22 22:09

OMG Ponies