Oracle中日期作为条件的查询有哪些?

Oracle中日期作为条件的查询有哪些?,第1张

Oracle中日期作为条件的查询有哪些?

Oracle中日期作为条件的查询有:1、范围日期的查询,代码为【where g_time between to_date()and to_date()】;2、等于某个日期的查询;3、当前日期的前几天和后几天的数据查询。

Oracle中日期作为条件的查询有:

1.范围日期的查询:

select * from goods
where g_time between
to_date('2018/12/26 10:01:59','yyyy-MM-dd hh:mi:ss')
and to_date('2018/12/26 10:05:17',' yyyy-MM-dd hh:mi:ss');

2.等于某个日期的查询:

select * from goods
where g_time=to_date('2018/12/26 10:05:17','yyyy-MM-dd hh:mi:ss');

3.当前日期的前几天和后几天的数据查询:

select * from goods
where g_time >= trunc(sysdate)-6  and < trunc(sysdate)-3;

为什么要用trunc(sysdate)

因为当前时间一般不会正好是0点,比如当前是11点,-6就是6天前的11 点开始

4.查询出每个月倒数第三天上架的商品信息:

select g.* from goods g where g.g_time=last_day(g.g_time)-2;

相关学习推荐:oracle数据库学习教程

以上就是Oracle中日期作为条件的查询有哪些?的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/704986.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-23
下一篇 2022-04-23

发表评论

登录后才能评论

评论列表(0条)

保存