date型別的內部結構
開發庫>select * from t_test;
------------ ---------- --------------------
06-JAN-13 100 中國
------------------- ---------- --------------------
2013-01-06 17:00:50 100 中國
--------------------------------------------------------------------------------
DUMP(N,16)
--------------------------------------------------------------------------------
DUMP(V,16)
--------------------------------------------------------------------------------
Typ=12 Len=7: 78,71,1,6,12,1,33
Typ=2 Len=2: c2,2
Typ=1 Len=4: d6,d0,b9,fa
--------------------------------
Typ=13 Len=8: 7,dd,1,6,11,0,32,0 --注意與上面不一致
-----------------
Typ=2 Len=2: c2,2
-------------------------
Typ=96 Len=4: d6,d0,b9,fa
開發庫>declare
2 d date;
3 begin
4 dbms_stats.convert_raw_value('78710106120133', d);
5 dbms_output.put_line(d);
6 end;
7 /
開發庫>/
2013-01-06 17:00:50
開發庫>declare
2 d date;
3 begin
4 dbms_stats.convert_raw_value('7dd010611003200', d);
5 dbms_output.put_line(d);
6 end;
7 /
9179-01-06 16:01:49
Internal representation of the DATE datatype
As with other datatypes, stored DATEs are always preceded by a length byte. The length byte is 0xFF for NULLs, or 7 bytes for known DATEs. The internal representation of DATEs is quite simple and can be easily seen using the dump function as follows.
SQL> create table dates (d date); Table created. SQL> insert into dates values (to_date('18/APR/2002 15:06:00', 'DD/MON/YYYY HH24:MI:SS')); 1 row created. SQL> select dump(d) from dates; DUMP(D) -------------------------------------------------------------------------------- Typ=12 Len=7: 120,102,4,18,16,7,1
The first two bytes represent the century and year respectively. Each of these bytes have an offset of 100 to allow for the negative centuries and years required for BC dates. For example, the byte pair 96,8 would represent the year 492 BC (the year of the battle of Marathon). The 3rd and 4th bytes represent the month and the day of that month respectively. The last three bytes represent the hour, minute, and second. Each of these time bytes have an offset of 1 to ensure that dates can never contain null bytes. So the contents of the seven bytes are as follows.
This only applies to stored dates. Oracle actually uses a slightly different representation internally when working with dates in memory.
byte 1: century + 100 byte 2: year + 100 byte 3: month byte 4: day of month byte 5: hour + 1 byte 6: minute + 1 byte 7: second + 1
SQL> select dump(to_date('18/APR/2002 15:06:00', 'DD/MON/YYYY HH24:MI:SS')) from dual; DUMP(TO_DATE('18/APR/200215:06:00 --------------------------------- Typ=13 Len=8: 210,7,4,18,15,6,0,0
Here the datatype number is 13, instead of 12. The memory structure has been padded to a 4-byte boundary. The time bytes do not have any offset. And the century and year are represented as a single signed two byte number. Because this dump was taken on a machine with a little-endian architecture, the bytes are reversed and should be read as 7,210 or 0x7D2, which is decimal 2002. The corresponding bytes for 492 BC would be 20,254. That reverses to 254,20 or 0xFE14, which is -492 in two's complement notation. These details are of course platform. specific.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/195110/viewspace-752205/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- JavaScript內部物件和Date物件JavaScript物件
- Date簡單型別的setter注入型別
- mongoose的date型別和timestamps的使用Go型別
- CNN、RNN、DNN的內部網路結構有什麼區別?CNNRNNDNN
- Redis 內部資料結構Redis資料結構
- 【REDO】Oracle redo內部結構Oracle Redo
- Kafak探究之路- 內部結構小結
- Redis字串型別內部編碼剖析Redis字串型別
- 物件導向--內部屬性型別物件型別
- 探索Kafka消費者的內部結構Kafka
- Redis資料結構的內部編碼Redis資料結構
- Redis 字串 內部資料結構Redis字串資料結構
- SQL Server日期資料型別DATE的使用SQLServer資料型別
- Redis 物件內部組織結構 —— 字典Redis物件
- FPGA內部硬體結構簡介FPGA
- gdb golang 檢視iface 內部結構Golang
- Mysql日期(DATE, TIME, DATETIME, TIMESTAMP)型別的比較MySql型別
- 【Hive】日期從整形轉為Date型別Hive型別
- 位元組碼檔案的內部結構之謎
- 關於結構體型別的學習結構體型別
- redis 資料結構和內部編碼Redis資料結構
- Java HashMap原理及內部儲存結構JavaHashMap
- PostgreSQL DBA(16) - WAL segment file內部結構SQL
- PostgreSQL DBA(17) - XLOG Record data內部結構SQL
- 放大器內部結構原理圖解圖解
- 資料庫內部儲存結構探索資料庫
- 泛型,內部類泛型
- Oracle date 型別比較和String比較Oracle型別
- SpringBoot Get 請求接收 Date 型別引數Spring Boot型別
- 見微知著 —— Redis 字串精緻的內部結構Redis字串
- 這高階玩意的的內部結構你瞭解多少
- 企業常見內部威脅的型別與應對方法型別
- Redis內部資料結構詳解(4)——ziplistRedis資料結構
- 【Redis】內部資料結構自頂向下梳理Redis資料結構
- BGP報文結構&型別、狀態型別
- 利用泛型模擬棧結構實現內部鏈式儲存結構泛型
- python 內建資料結構-數值型Python資料結構
- SpringBoot 通過Converter轉化 date型別引數Spring Boot型別
- SCI論文的型別以及寫作結構分析型別