在Pl/SQL的datetime字段上仅更新日期 [英] Update only date on datetime field on Pl/SQL

查看:94
本文介绍了在Pl/SQL的datetime字段上仅更新日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我需要更新Oracle数据库上的某些日期,该字段是日期时间,但是我只希望更新日期,而不要保留时间.查询如下:

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?

推荐答案

您可以使用:

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

这篇关于在Pl/SQL的datetime字段上仅更新日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆