DB2 Timestamp选择语句 [英] DB2 Timestamp select statement
问题描述
我正在尝试运行一个简单的查询,该查询基于时间戳获取我的数据,如下所示:
I am trying to run a simple query which gets me data based on timestamp, as follows:
SELECT *
FROM <table_name>
WHERE id = 1
AND usagetime = timestamp('2012-09-03 08:03:06')
WITH UR;
这似乎没有向我返回记录,而该记录存在于数据库中,标识为id = 1.
This does not seem to return a record to me, whereas this record is present in the database for id = 1.
我在做什么错了?
列usetime的数据类型正确,设置为时间戳.
The datatype of the column usagetime is correct, set to timestamp.
推荐答案
@bhamby是正确的.通过将时间戳值保留微秒,您的查询将仅在2012年9月3日08:03:06.000000的使用时间上匹配
@bhamby is correct. By leaving the microseconds off of your timestamp value, your query would only match on a usagetime of 2012-09-03 08:03:06.000000
如果您没有从上一个查询中捕获的完整时间戳值,则可以指定一个范围谓词,该谓词将与该时间的任何微秒值匹配:
If you don't have the complete timestamp value captured from a previous query, you can specify a ranged predicate that will match on any microsecond value for that time:
...WHERE id = 1 AND usagetime BETWEEN '2012-09-03 08:03:06' AND '2012-09-03 08:03:07'
或
...WHERE id = 1 AND usagetime >= '2012-09-03 08:03:06'
AND usagetime < '2012-09-03 08:03:07'
这篇关于DB2 Timestamp选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!