Oracle的转储(systimestamp)字节的含义

时间:2015-07-31 09:05:47

标签: oracle oracle11g time-format systimestamp

我试图了解数据库中设置的时间戳的字节是什么意思。如何计算它们以生成更易读的日期?

我使用以下查询来获取我需要的数据:

SELECT systimestamp
    ,DUMP (systimestamp)
    ,sessiontimezone
FROM dual;

以上查询的输出是:

+-------------------------------------+-----------------------------------------------------------------+------------------+
|            systimestamp             |                       dump(systimestamp)                        | sessiontimezone  |
+-------------------------------------+-----------------------------------------------------------------+------------------+
| 31-JUL-15 08.55.06.157047000 +00:00 | Typ=188 Len=20: 223,7,7,31,8,55,6,0,216,88,92,9,0,0,5,0,0,0,0,0 | Europe/Bucharest |
+-------------------------------------+-----------------------------------------------------------------+------------------+

我在网上找到了一些资源来解释字节的含义( here ),但规则在我的方案中并不匹配。

例如:223不是世纪+100等。

我尝试这样做的原因是,在将timestamp(3)列中的值与systimestamp进行比较时,我遇到了一个问题,而我正在尝试写一个脚本来验证我的问题/解决方案是否相同as explained here

感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

有各种表面上相似但内部不同的日期时间数据类型。 systimestamp是188类型(并有时区信息);时间戳文字是类型187,没有时区信息,188是它;普通时间戳列是180型:

select dump(systimestamp) from dual;

DUMP(SYSTIMESTAMP)                                                             
--------------------------------------------------------------------------------
Typ=188 Len=20: 223,7,7,31,9,50,28,11,128,203,79,35,1,0,5,0,0,0,0,0             

select dump(timestamp '2015-07-31 08:55:06.157047 +00:00') from dual;

DUMP(TIMESTAMP'2015-07-3108:55:06.157047+00:00')              
---------------------------------------------------------------
Typ=188 Len=20: 223,7,7,31,8,55,6,0,216,88,92,9,0,0,5,0,0,0,0,0

select dump(timestamp '2015-07-31 08:55:06.157047') from dual;

DUMP(TIMESTAMP'2015-07-3108:55:06.157047')                    
---------------------------------------------------------------
Typ=187 Len=20: 223,7,7,31,8,55,6,0,216,88,92,9,0,0,3,0,0,0,0,0

create table t (ts timestamp);
insert into t (ts) values (timestamp '2015-07-31 08:55:06.157047');
select dump(ts) from t;

DUMP(TS)                                                                       
--------------------------------------------------------------------------------
Typ=180 Len=11: 120,115,7,31,9,56,7,9,92,88,216                                 

其中,只有时间戳列使用您链接到的文章中的内部格式,使用年份超过100的表示法。

对于其他人,第一个字节是base-256修饰符,第二个字节是256年的基数;所以你会把它解释为

223 + (7 * 256) = 2015

您可以在My Oracle Support文档69028.1中阅读有关内部存储的更多信息。那个,以及在评论中链接的早期答案,指的是两种日期类型,但是时间戳被视为相同的秒数,其余部分可以推断为187/188型 - 无论如何是小数秒部分:

Byte 1 - Base 256 year modifier: 223
2      - Base 256 year: 7 (256 * 7 = 1792 + 223 = 2015)
3      - Month: 7
4      - Day: 31
5      - Hours: 8
6      - Minutes: 55
7      - Seconds: 6
8      - Unused?
9      - Base 256 nanoseconds: 216
10     - Base 256 ns modifier 1: 256 * 88 = 22528
11     - Base 256 ns modifier 2: 256 * 256 * 92 = 6029312
12     - Base 256 ns modifier 3: 256 * 256 * 256 * 9 = 150994944
           => actual nanoseconds = 216 + 22528 + 6029312 + 150994944 
           => 157047000
13-20  - Time zone data?

对于类型120,小数秒是相同的,但字节相反。

相关问题