In the development of SQL, filter date is often encountered in the situation, how to efficiently filter out the date period? This article is validated by experiments:
Method One, compare dates into strings by To_char
To_char (cr.contractenddate, ' yyyy-mm-dd ') >= ' 2014-11-13 '
and To_char (cr.contractenddate, ' yyyy-mm-dd ') <= ' 2015-11-19 '
Time: 0.171s
Method Two, by To_date to convert the string to a date for comparison
Cr.contractenddate >= to_date (' 2014-11-13 ', ' yyyy-mm-dd ')
and Cr.contractenddate <= to_date (' 2015-11-19 ', ' yyyy-mm-dd ')
Time: 0.093s
Method Three, through the database keyword between and comparison
Cr.contractenddate
Between To_date (' 2014-11-13 ', ' yyyy-mm-dd ') and to_date (' 2015-11-19 ', ' yyyy-mm-dd ')
Time: 0.078s
Summary: Methods a time-consuming body now needs to compare each character of a string one by another;
Method two time-consuming reflected in >= and <=;
Recommended Use Method Three
Performance Comparison of Oracle database date filtering methods