SQL 为什么将 LIKE 与 TIMESTAMPS 一起使用在 DB2 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10009553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
why using LIKE with TIMESTAMPS do not work in DB2
提问by f00sa
i have problem using LIKE
structure in DB2
:
for example:
我在使用LIKE
结构时遇到问题DB2
:例如:
select * from TEST where TIME LIKE '2012-03-04-%'
FYI. - TIME
is TIMESTAMP
data type.
供参考。-TIME
是TIMESTAMP
数据类型。
why using LIKE
with TIMESTAMPS
do not work?
为什么使用LIKE
withTIMESTAMPS
不起作用?
Additional info: i want to extract data from one single day provided by user in select statement.
附加信息:我想从用户在 select 语句中提供的一天中提取数据。
回答by beny23
Just expanding on @mortb's answer, I'd either use BETWEEN
or
只是扩展@mortb 的答案,我要么使用BETWEEN
要么
WHERE time >= '2012-03-04' AND time < '2012-03-05'
The advantage of using BETWEEN
or a comparison that using casts
and LIKE
will mean that if there is an index on time
it wouldn't be able to be used due to the casting.
使用BETWEEN
或比较使用casts
和的优点LIKE
将意味着如果有索引,time
则由于铸造而无法使用。
回答by mortb
LIKE is for string (char, varchar) datatypes. Use WHERE time BETWEEN '2012-03-04' AND '2012-03-04 23:59:59.998'
LIKE 用于字符串(char、varchar)数据类型。用WHERE time BETWEEN '2012-03-04' AND '2012-03-04 23:59:59.998'
回答by Prabhu Kandasamy
You can use like this where time between to_date('2016-06-17 00:00:00','yyyy-mm-dd HH24:MI:SS') and to_date('2016-06-18 00:00:00','yyyy-mm-dd HH24:MI:SS')
您可以像这样使用 to_date('2016-06-17 00:00:00','yyyy-mm-dd HH24:MI:SS') 和 to_date('2016-06-18 00:00:00') 之间的时间','yyyy-mm-dd HH24:MI:SS')