https://www.cnblogs.com/simeone/p/4189264.html
1.查询当天的时间
select * from test where trunc(create_time)=trunc(sysdate)
其中trunc(sysdate)为固定写法,trunc(表的字段,变化的,根据自己的表,比如我这里就是根据创建时间去查询当天的时间)
用法如下:
select trunc(sysdate) from test--2021-8-12 今天的日期为2021-8-12
select trunc(sysdate, 'mm') from test--2021-12-1 返回当月第一天.
select trunc(sysdate,'yy') from test--2021-1-1 返回当年第一天
select trunc(sysdate,'dd') from test--2021-3-18 返回当前年月日
select trunc(sysdate,'yyyy') from test--2021-1-1 返回当年第一天
select trunc(sysdate,'d') from test--2021-12-21 (星期天)返回当前星期的第一天
select trunc(sysdate, 'hh') from test --2021-8-12 22:00:00 当前时间为14:41
select trunc(sysdate, 'mi') from test--2021-8-12 22:17:00 TRUNC()函数没有秒的精
2、查询字段不为空
查询A表中b1字段不为空的数据:select * from 表名 where 字段名 is not null
查询A表中b1字段为空的数据:select * from 表名 where 字段名 is null
3、oracle返回限制条数
oracle返回限制条数,用关键字rownum
,这是写死的。
比如查询B表中的数据,返回前十条:select * from 表名 where rownum < 11
4、oracle查询指定时间范围内的数据
指定时间范围内的数据查询:SELECT * FROM 表名 WHERE to_char(列名,'yyyy-mm-dd') BETWEEN 起始时间 AND 结束时间
其中to_char(GRE_DATE,'yyyy-mm-dd') between '2021-08-10' and '2021-08-15';
GRE_DATE为查询字段,日期根据自己的实际情况修改就可以了。
select * from A where to_char(GRE_DATE,'yyyy-mm-dd') between '2021-08-10' and '2021-08-15';
5、oracle查询指定字段的部分字段
oracle查询指定字段的部分字段,可以使用to_char(列名,列名的格式)
select t.*, to_char(v_date, 'yyyy-mm-dd') v_date_mon1,trunc(v_date, 'mm') v_date_mon2 from A as t