Oracle在DATE使用LIKE'%' [英] Oracle use LIKE '%' on DATE

查看:309
本文介绍了Oracle在DATE使用LIKE'%'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表myTab具有列startDate,其数据类型为"DATE".此列中的数据以dd.mm.yyyy的形式存储.

My table myTab has the column startDate, which has the datatype "DATE". The data in this column are stored like dd.mm.yyyy.

现在,我正在尝试通过此查询获取数据:

Now I'm trying to get data with this query:

SELECT * FROM myTab WHERE startDate like '%01.2015"

不知何故,我也不知道为什么.

Somehow it doesn't work and I don't know why.

希望有人可以提供帮助.

Hope someone can help.

推荐答案

要在日期上进行文本搜索,您必须将日期转换为文本.

To make a text search on the date you would have to convert the date to text.

如果您为要查找的内容计算开始和结束日期并获得它们之间的所有内容,则效率会更高.这样,它就可以作为数字比较而不是文本模式匹配来完成,并且如果存在索引,则可以利用索引:

It's more efficient if you calculate the first and last date for what you want to find and get everything between them. That way it's done as numeric comparisons instead of a text pattern match, and it can make use of an index if there is one:

SELECT * FROM myTab WHERE startDate >= DATE '2015-01-01' AND startDate < DATE '2015-02-01'

这篇关于Oracle在DATE使用LIKE'%'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆