首页 > 解决方案 > Oracle - 更新日期字段

问题描述

我有一个schedule_finish我想更新的字段,但是当我这样做时,前端的日期显示在数据库中的日期之后的一天。IE。当我将日期更新为 时30-AUG-19,前端显示的是 8 月 29 日。我可以通过在我想要更新字段的日期上添加一秒来解决这个问题,但我不确定在这种情况下该怎么做。

这是我的 SQL:

update inv_investments
set schedule_finish = TRUNC('30-AUG-19') + 1/(24*60*60)
where id=5064001;

但这给了我错误:

ORA-00932: inconsistent datatypes: expected DATE got NUMBER

但是,例如,如果我这样做,它会起作用:

update inv_investments
set schedule_finish = TRUNC(updated_date) + 1/(24*60*60)
where id=5064001;

/* where updated_date field is '30-AUG-19' */
/* shows same date on both back and front end as desired */

有没有办法将我想要更新字段的日期存储在变量中,然后在更新语句中引用该变量,和/或有更好的方法来实现这一点?

提前致谢

标签: sqloraclesql-update

解决方案


您正在添加到一个字符串。字符串必须转换为日期

update inv_investments
  set schedule_finish = TO_DATE('30-AUG-19','dd-MON-yy') + 1/(24*60*60)
  where id=5064001;

推荐阅读