开发者

Update only date on datetime field on Pl/SQL

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 da开发者_JAVA百科te but i want the hour to be left the same, any thoughts?


You could use:

UPDATE TABLE
   SET field = TO_DATE('07312010' || ' ' || TO_CHAR(field, 'HH24:MI:SS'),
                       'MMDDYY HH24:MI:SS');


In Oracle the blank is a minor issue , I modified it a little bit.

/* Formatted on 4/26/2017 5:56:31 AM (QP5 v5.115.810.9015) */

UPDATE  telco_attendee
   SET startdate =
TO_DATE(  (  TO_CHAR(startdate, 'DD/MM/YYYY')
|| 
TO_CHAR(starttime, 'HH24:MI:SS')  )  ,'DD/MM/YYYYHH24:MI:SS')   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜