Home >Database >Mysql Tutorial >Oracle取今天今年当月的数据

Oracle取今天今年当月的数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:27:441170browse

Oracle中取今天的数据,之前使用到where to_char(t.t_created_tm,

Oracle中取今天的数据,之前使用到where to_char(t.t_created_tm, 'YYYY-MM-DD')= to_char(SYSDATE, 'YYYY-MM-DD');
 
这种方式效率低下,而且对t.t_created_tm即使建了索引,但是因为对他进行了函数封装后比较,查询时索引也用不上。
 
这里介绍可以使用TRUNC(SYSDATE)=当天来比较过滤数据,,达到取今天数据的效果。

SELECT TRUNC(SYSDATE) FROM DUAL;
--TRUNC(SYSDATE)
2013/1/5

下面的方法比较好。

SELECT * FROM TBL_STEP T WHERE T.T_CREATE_TM >= TRUNC(SYSDATE);

如果取当年的数据

SELECT * FROM TBL_STEP T WHERE T.T_CREATE_TM >= TRUNC(SYSDATE,'YYYY');

当月的数据

SELECT * FROM TBL_STEP T WHERE T.T_CREATE_TM>=TRUNC(SYSDATE, 'MM') AND T.T_CREATE_TM

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Oracle级联操作Next article:ORA-27102: out of memory 故障