db2查询时间戳数据类型的奇怪行为 [英] Strange behaviour for db2 query for timestamp data type

查看:172
本文介绍了db2查询时间戳数据类型的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询db2中的timestamp数据类型。
我在下面写了查询

I want to query for timestamp data type in db2. I wrote query below

从样本中选择*,其中LASTMODIFIEDDATE = timestamp('2012-04-03 07:59:50' )

我没有得到上述查询的任何结果,然后我尝试

I didn't get any result for above query , then I tried

从样本中选择*,其中LASTMODIFIEDDATE>时间戳('2012-04-03 07:59:50')

在上面的查询中,我得到了匹配时间戳的结果2012-04- 03 07:59:50'加上更大的时间戳值,例如2012-04-03 08:59:50。

In above query I got results matching timestamp '2012-04-03 07:59:50' plus for greater values of timestamp, e.g '2012-04-03 08:59:50'.

如果我获得 >'运算符,那么为什么我没有得到'='运算符的结果?
任何理由或我写错误查询?

If I am getting results for '>' operator then why not I am not getting any results for '=' operator ? Any reasons or am I writing wrong query ?

谢谢!

推荐答案

否,DB2存储时间戳的完整值,包括小数秒。您可能希望将系统显示时间戳的格式更改为包含毫秒的内容。

No, DB2 stores the full value of the timestamp, including the fractional seconds. You may wish to change the format the system displays timestamps in to something that includes milliseconds.

尝试使用此代码:

SELECT * 
FROM Sample
WHERE lastModifiedDate >= TIMESTAMP('2012-04-03 07:59:50')
AND lastModifiedDate < TIMESTAMP('2012-04-03 07:59:50)' + 1 SECONDS

除非你有时间戳的完整包括毫秒,您将获得一个范围 - 访问一系列数据时,使用下限包含绑定排他'。

Unless you have the full value of the timestamp, including milliseconds, you're going to be getting a range - when accessing a range of data, use 'lower-bound inclusive, upper-bound exclusive'.

这篇关于db2查询时间戳数据类型的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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