Oracle在DATE使用LIKE'%' [英] Oracle use LIKE '%' on DATE
问题描述
我的表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屋!