Oracle 中的时间戳排序顺序

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

Timestamp sort order in Oracle

oraclesortingtimestamp

提问by Dima

I've noticed some strange sort order when sorting by timestamp. First it sorts by time portion of the timestamp and then, for the records with the same time, date used for sort.

在按时间戳排序时,我注意到一些奇怪的排序顺序。首先它按时间戳的时间部分排序,然后对于具有相同时间的记录,排序所用的日期。

For me it looks completely wrong. Is there any way to tell Oracle to sort by date and then by time?

对我来说,这看起来完全错误。有什么方法可以告诉 Oracle 按日期然后按时间排序?

Thanks.

谢谢。

Field is defined as TIMESTAMP(6), without timezone. Here is the sorting result:

字段定义为 TIMESTAMP(6),没有时区。下面是排序结果:

10-JAN-11 11.18.36.368000000 AM
09-JAN-11 11.18.33.700000000 AM
08-JAN-11 11.18.33.704000000 AM
07-JAN-11 11.18.33.700000000 AM
06-JAN-11 11.17.40.705000000 AM
05-JAN-11 11.17.42.611000000 AM
04-JAN-11 11.17.40.723000000 AM
02-JAN-11 04.45.09.553000000 PM
01-JAN-11 04.45.08.447000000 PM
31-DEC-10 04.45.08.447000000 PM
30-DEC-10 04.35.22.153000000 PM
29-DEC-10 04.30.25.334000000 PM
12-JAN-11 12.00.00.000000000 AM
11-JAN-11 12.00.00.000000000 AM
10-JAN-11 12.00.00.000000000 AM
09-JAN-11 12.00.00.000000000 AM
08-JAN-11 12.00.00.000000000 AM
07-JAN-11 12.00.00.000000000 AM

Here is the query:

这是查询:

select period_end from table_name where entity_id=102167 order by period_end desc;

回答by Rob van Wijk

Dima,

迪玛,

Your timestamp format shows all components of the timestamp, except one: the century. Your last six rows must be from a previous century.

您的时间戳格式显示了时间戳的所有组成部分,除了一个:世纪。您的最后六行必须来自上个世纪。

Regards,
Rob.

问候,
罗伯。

回答by René Nyffenegger

You probable have a timestamp with timezone.

你可能有一个timestamp with timezone.