对 Oracle 时间戳使用 BETWEEN 或 <=, >=

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4258529/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:01:12  来源:igfitidea点击:

Using BETWEEN or <=, >= for Oracle timestamps

sqloracleoracle10g

提问by Russell

My Oracle table has a column tmstpwith the TIMESTAMP(3) WITH TIME ZONEdatatype.

我的Oracle表有一栏tmstpTIMESTAMP(3) WITH TIME ZONE数据类型。

When I run the following query

当我运行以下查询时

SELECT COUNT(column1) 
  FROM table1 
 WHERE tmstp BETWEEN to_timestamp_tz('10-OCT-10 05.00.00.000000000 AM -05:00', 'DD-MON-RR HH.MI.SSXFF AM TZR')
                 AND to_timestamp_tz('11-OCT-10 04.59.59.999999999 AM -05:00', 'DD-MON-RR HH.MI.SSXFF AM TZR');

it gives about twice the count as the following query:

它提供的计数大约是以下查询的两倍:

SELECT COUNT(column1) 
  FROM table1 
 WHERE tmstp >= to_timestamp_tz('10-OCT-10 05.00.00.000000000 AM -05:00', 'DD-MON-RR HH.MI.SSXFF AM TZR') 
   AND tmstp <= to_timestamp_tz('11-OCT-10 04.59.59.999999999 AM  -05:00', 'DD-MON-RR HH.MI.SSXFF AM TZR');

I thought they should give equivalent results. Any input on what might be happening? How should I debug this?

我认为他们应该给出相同的结果。关于可能发生的事情的任何意见?我应该如何调试这个?

采纳答案by Russell

Sorry for the trouble. I figured it out. My question is actually flawed too because I edited it to hide confidential data.

抱歉,添麻烦了。我想到了。我的问题实际上也有缺陷,因为我对其进行了编辑以隐藏机密数据。

There was an extra whitespace between the AM and timezone offset in one of the queries and that caused different results.

在其中一个查询中的 AM 和时区偏移之间有一个额外的空格,这导致了不同的结果。

Stupid me.

愚蠢的我。

So if the timestamp string that is converted is a bit off with whitespaces, the answers might be off.

因此,如果转换的时间戳字符串与空格有点偏离,则答案可能会偏离。