sql - 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 */
有没有办法将我想要更新字段的日期存储在变量中,然后在更新语句中引用该变量,和/或有更好的方法来实现这一点?
提前致谢
解决方案
您正在添加到一个字符串。字符串必须转换为日期
update inv_investments
set schedule_finish = TO_DATE('30-AUG-19','dd-MON-yy') + 1/(24*60*60)
where id=5064001;
推荐阅读
- python - 如何使用 fastAPI 显示来自 SqlAlchemy Query 的列表数据
- google-apps-script - 在 Google Apps 脚本中计算 CRC-16/CCITT-FALSE
- c# - 是否有任何黑客方法可以访问声明为内部的父属性?
- node.js - 无法写入工作区设置,因为 .. 不是注册配置
- java - 将图像转换为 base64 kotlin 时出现 FileNotFoundException
- javascript - 如何将 JSON 日期类型中的此预请求脚本转换为时间类型
- python - 如何在dict中获取特定的键值
- java - 如何构建可执行的 JavaFX 11 应用程序
- javascript - PHP 和 Javascript 交叉兼容的序列化器
- python - 如何在网格上聚类一组 3D 点?