万能的 v 友们 oracle 时间查询求助

2019-03-14 10:27:30 +08:00
 chaodada

select * from 表名 t where trunc(t.提交时间) between trunc(sysdate-1) and trunc(sysdate-1)

进行时间段查询
但是 “提交时间” 这个字段在数据库存储的是 13-MAR-19 这种类型 , 我前端传来的数据是这样的 2019-03-14 我应该在语句中怎么写呢 本人小白。。

2496 次点击
所在节点    Oracle
3 条回复
l00t
2019-03-14 10:49:35 +08:00
你先别管它存的形式是什么,先关心下它这个字段是什么类型。
chaodada
2019-03-14 11:03:31 +08:00
@l00t 大佬时间是 DATE 类型 。。。
l00t
2019-03-14 11:13:41 +08:00
时间类型就直接统一成时间类型来用,不用管形式。

考虑到你是小白,我给你例子:

select * from 表名 t where t.提交时间 between sysdate-1 and sysdate;

你上面那几个 trunc 真的没问题吗?本身你给的时间就是到天,sysdate 默认也是到天,你再 trunc 一下还是到天,没有任何意义啊。你的 between 条件里两个都是 sysdate -1, 你也再看看到底对不对。如果你的 between 里面有一个是你前端来的数据,那你怎样写:


select * from 表名 t where t.提交时间 between to_date('2019-03-14', 'yyyy-mm-dd') and sysdate;

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/544432

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX