Oracle中日期作为条件的查询有:1、范围日期的查询,代码为【where g_time between to_date()and to_date()】;2、等于某个日期的查询;3、当前日期的前几天和后几天的数据查询。
Oracle中日期作为条件的查询有:
1.范围日期的查询:
1 2 3 4 | 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.等于某个日期的查询:
1 2 | select * from goods
where g_time=to_date( '2018/12/26 10:05:17' , 'yyyy-MM-dd hh:mi:ss' );
|
3.当前日期的前几天和后几天的数据查询:
1 2 | select * from goods
where g_time >= trunc(sysdate)-6 and < trunc(sysdate)-3;
|
为什么要用trunc(sysdate)
呢
因为当前时间一般不会正好是0点,比如当前是11点,-6就是6天前的11 点开始
4.查询出每个月倒数第三天上架的商品信息:
1 | select g.* from goods g where g.g_time=last_day(g.g_time)-2;
|
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。