简体   繁体   English

Oracle 11g - 带有TimeStamp的Sql

[英]Oracle 11g - Sql with TimeStamp

I have a table named Evrak and it has two columns which are Product_Date [timestamp(6)] and Evrak_Name[varchar2(50)]. 我有一个名为Evrak的表,它有两列,分别是Product_Date [timestamp(6)]和Evrak_Name [varchar2(50)]。 There is a record which name is Evrak Test and Product_Date is 记录的名称是Evrak Test和Product_Date
25-APR-12 12.00.00.000000000 PM. 25-APR-12 12.00.00.000000000 PM。

When i want to run a query like ; 当我想运行查询时;

select * from Evrak Where Evrak.Product_Date  = TO_TIMESTAMP ('25.04.2012:00:00:00','DD.MM.YYYY:HH24:MI:SS')

It does return a null record, i' ve tried to change format type and have used to_date, to_char methods but did not managed to get the record. 它确实返回一个空记录,我试图改变格式类型并使用to_date,to_char方法,但没有设法得到记录。 What am i missing here ? 我在这里失踪了什么? or is there any special usage while quering a timestamp column? 或者在查询时间戳列时是否有任何特殊用法?

Try: 尝试:

select * 
 from Evrak 
Where Evrak.Product_Date  = TO_TIMESTAMP ('25.04.2012:12:00:00','DD.MM.YYYY:HH24:MI:SS')

Since you want 25-APR-12 12.00.00.000000000 PM and not 25-APR-12 12.00.00.000000000 AM 由于你想要25-APR-12 12.00.00.000000000 PM而不是25-APR-12 12.00.00.000000000 AM

Time stamps are finicky. 时间戳很挑剔。 Like floating point numbers, there may be insignificant bits that affect comparisons. 与浮点数一样,可能存在影响比较的无关紧要的位。

I would suggest returning things within a range. 我建议在一定范围内归还。 For instance, the following query returns time stamps within one second. 例如,以下查询在一秒内返回时间戳。

select *
from Evrak
Where abs(Evrak.Product_Date - TO_TIMESTAMP ('25.04.2012:00:00:00', 'DD.MM.YYYY:HH24:MI:SS')) < 1.0/(24*60*60)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM