为什么将 LIKE 与 TIMESTAMPS 一起使用在 DB2 中不起作用 [英] why using LIKE with TIMESTAMPS do not work in DB2

查看:11
本文介绍了为什么将 LIKE 与 TIMESTAMPS 一起使用在 DB2 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 DB2 中使用 LIKE 结构时遇到问题:例如:

i have problem using LIKE structure in DB2: for example:

select * from TEST where TIME LIKE '2012-03-04-%'

仅供参考.- TIMETIMESTAMP 数据类型.

FYI. - TIME is TIMESTAMP data type.

为什么使用 LIKETIMESTAMPS 不起作用?

why using LIKE with TIMESTAMPS do not work?

附加信息:我想从用户在 select 语句中提供的一天中提取数据.

Additional info: i want to extract data from one single day provided by user in select statement.

推荐答案

只是扩展@mortb 的答案,我会使用 BETWEEN

Just expanding on @mortb's answer, I'd either use BETWEEN or

WHERE time >= '2012-03-04' AND time < '2012-03-05'

使用 BETWEEN 的优势或使用 castsLIKE 的比较意味着如果在 time 上有索引 由于强制转换,它无法使用.

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.

这篇关于为什么将 LIKE 与 TIMESTAMPS 一起使用在 DB2 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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