Home  >  Article  >  Database  >  Oracle数据库日期过滤方法性能比较

Oracle数据库日期过滤方法性能比较

WBOY
WBOYOriginal
2016-06-07 16:08:001375browse

Oracle数据库日期过滤方法性能比较。在开发SQL时,过滤日期段是经常遇到的情况,如何高效的过滤出日期段?本文通过实验进行验证:

Oracle数据库日期过滤方法性能比较

在开发SQL时,过滤日期段是经常遇到的情况,,如何高效的过滤出日期段?本文通过实验进行验证:

方法一、通过to_char将日期转换成字符串进行比较

to_char(cr.contractenddate, 'YYYY-MM-DD') >= '2014-11-13'

and to_char(cr.contractenddate, 'YYYY-MM-DD')

耗时:0.171s

方法二、通过to_date将字符串转换成日期进行比较

cr.contractenddate >= to_date('2014-11-13', 'YYYY-MM-DD')

and cr.contractenddate

耗时:0.093s

方法三、通过数据库关键字between  and 进行比较

cr.contractenddate

between to_date('2014-11-13', 'YYYY-MM-DD') and to_date('2015-11-19', 'YYYY-MM-DD')

耗时:0.078s

总结:方法一耗时体现在需要逐个比较字符串的每个字符;

方法二耗时体现在>= 和

推荐使用方法三

本文永久更新链接地址:

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