Oracle基本資料型別儲存格式淺析(三)——日期型別(二)
Oracle基本資料型別儲存格式淺析(三)——日期型別(二)
這篇文章描述TIMESTAMP型別的資料在Oracle中是以何種格式存放的。
下面透過一個例子進行說明。
SQL> create table test_time (col_time timestamp);
表已建立。
SQL> insert into test_time values (to_timestamp('0001-1-1 0:0:0.0', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('2000-1-1 0:0:0.0', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('9999-12-31 23:59:59.999999', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('-0001-1-1 0:0:0.0', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('-0100-3-4 13:2:3.234015', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (systimestamp);
已建立 1 行。
SQL> insert into test_time values (to_timestamp('2000-1-1 0:0:0.123456789', 'syyyy-mm-dd hh24:mi:ss.ff9'));
已建立 1 行。
SQL> commit;
提交完成。
SQL> select to_char(col_time, 'syyyy-mm-dd hh24:mi:ss.ff9') time, dump(col_time) dump_time
2 from test_time;
TIME DUMP_TIME
------------------------------ ----------------------------------------------------
0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,101,1,1,1,1,1
2000-01-01 00:00:00.000000000 Typ=180 Len=7: 120,100,1,1,1,1,1
9999-12-31 23:59:59.999999000 Typ=180 Len=11: 199,199,12,31,24,60,60,59,154,198,24
-0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,99,1,1,1,1,1
-0100-03-04 13:02:03.234015000 Typ=180 Len=11: 99,100,3,4,14,3,4,13,242,201,24
2004-12-15 16:14:52.738000000 Typ=180 Len=11: 120,104,12,15,17,15,53,43,252,252,128
2000-01-01 00:00:00.123457000 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,232
已選擇7行。
與DATE型別對比可以發現,對於TIMESTAMP型別,如果不包含微秒資訊或者微秒值為0,那麼儲存結果和DATE完全相同。當微秒值為0時,Oracle為了節省空間,不會儲存微秒資訊。
如果毫秒值不為0,Oracle把微秒值當作一個9位數的數字來儲存。
比如999999000,儲存為59,154,198,24。234015000儲存為13,242,201,24。
SQL> select to_char(999999000, 'xxxxxxxxxx') from dual;
TO_CHAR(999
-----------
3b9ac618
SQL> select to_number('3b', 'xxx') one, to_number('9a', 'xxx') two,
2 to_number('c6', 'xxx') three, to_number('18', 'xxx') four from dual;
ONE TWO THREE FOUR
---------- ---------- ---------- ----------
59 154 198 24
SQL> select to_char(234015000, 'xxxxxxxx') from dual;
TO_CHAR(2
---------
df2c918
SQL> select to_number('d', 'xxx') one, to_number('f2', 'xxx') two,
2 to_number('c9', 'xxx') three, to_number('18', 'xxx') four from dual;
ONE TWO THREE FOUR
---------- ---------- ---------- ----------
13 242 201 24
另外,注意一點,不指定精度的情況下,TIMESTAMP預設取6位。長度超過6位,會四捨五入到6位。如果希望儲存9位的TIMESTAMP,必須明確指定精度。
SQL> alter table test_time modify (col_time timestamp(9));
表已更改。
SQL> insert into test_time values (to_timestamp('2000-1-1 0:0:0.123456789', 'syyyy-mm-dd hh24:mi:ss.ff9'));
已建立 1 行。
SQL> select to_char(col_time, 'syyyy-mm-dd hh24:mi:ss.ff9') time, dump(col_time) dump_time
2 from test_time;
TIME DUMP_TIME
------------------------------ ---------------------------------------------------
0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,101,1,1,1,1,1
2000-01-01 00:00:00.000000000 Typ=180 Len=7: 120,100,1,1,1,1,1
9999-12-31 23:59:59.999999000 Typ=180 Len=11: 199,199,12,31,24,60,60,59,154,198,24
-0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,99,1,1,1,1,1
-0100-03-04 13:02:03.234015000 Typ=180 Len=11: 99,100,3,4,14,3,4,13,242,201,24
2004-12-15 16:14:52.738000000 Typ=180 Len=11: 120,104,12,15,17,15,53,43,252,252,128
2000-01-01 00:00:00.123457000 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,232
2000-01-01 00:00:00.123456789 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,21
已選擇8行。
下面透過一個例子進行說明。
SQL> create table test_time (col_time timestamp);
表已建立。
SQL> insert into test_time values (to_timestamp('0001-1-1 0:0:0.0', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('2000-1-1 0:0:0.0', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('9999-12-31 23:59:59.999999', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('-0001-1-1 0:0:0.0', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (to_timestamp('-0100-3-4 13:2:3.234015', 'syyyy-mm-dd hh24:mi:ss.ff'));
已建立 1 行。
SQL> insert into test_time values (systimestamp);
已建立 1 行。
SQL> insert into test_time values (to_timestamp('2000-1-1 0:0:0.123456789', 'syyyy-mm-dd hh24:mi:ss.ff9'));
已建立 1 行。
SQL> commit;
提交完成。
SQL> select to_char(col_time, 'syyyy-mm-dd hh24:mi:ss.ff9') time, dump(col_time) dump_time
2 from test_time;
TIME DUMP_TIME
------------------------------ ----------------------------------------------------
0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,101,1,1,1,1,1
2000-01-01 00:00:00.000000000 Typ=180 Len=7: 120,100,1,1,1,1,1
9999-12-31 23:59:59.999999000 Typ=180 Len=11: 199,199,12,31,24,60,60,59,154,198,24
-0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,99,1,1,1,1,1
-0100-03-04 13:02:03.234015000 Typ=180 Len=11: 99,100,3,4,14,3,4,13,242,201,24
2004-12-15 16:14:52.738000000 Typ=180 Len=11: 120,104,12,15,17,15,53,43,252,252,128
2000-01-01 00:00:00.123457000 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,232
已選擇7行。
與DATE型別對比可以發現,對於TIMESTAMP型別,如果不包含微秒資訊或者微秒值為0,那麼儲存結果和DATE完全相同。當微秒值為0時,Oracle為了節省空間,不會儲存微秒資訊。
如果毫秒值不為0,Oracle把微秒值當作一個9位數的數字來儲存。
比如999999000,儲存為59,154,198,24。234015000儲存為13,242,201,24。
SQL> select to_char(999999000, 'xxxxxxxxxx') from dual;
TO_CHAR(999
-----------
3b9ac618
SQL> select to_number('3b', 'xxx') one, to_number('9a', 'xxx') two,
2 to_number('c6', 'xxx') three, to_number('18', 'xxx') four from dual;
ONE TWO THREE FOUR
---------- ---------- ---------- ----------
59 154 198 24
SQL> select to_char(234015000, 'xxxxxxxx') from dual;
TO_CHAR(2
---------
df2c918
SQL> select to_number('d', 'xxx') one, to_number('f2', 'xxx') two,
2 to_number('c9', 'xxx') three, to_number('18', 'xxx') four from dual;
ONE TWO THREE FOUR
---------- ---------- ---------- ----------
13 242 201 24
另外,注意一點,不指定精度的情況下,TIMESTAMP預設取6位。長度超過6位,會四捨五入到6位。如果希望儲存9位的TIMESTAMP,必須明確指定精度。
SQL> alter table test_time modify (col_time timestamp(9));
表已更改。
SQL> insert into test_time values (to_timestamp('2000-1-1 0:0:0.123456789', 'syyyy-mm-dd hh24:mi:ss.ff9'));
已建立 1 行。
SQL> select to_char(col_time, 'syyyy-mm-dd hh24:mi:ss.ff9') time, dump(col_time) dump_time
2 from test_time;
TIME DUMP_TIME
------------------------------ ---------------------------------------------------
0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,101,1,1,1,1,1
2000-01-01 00:00:00.000000000 Typ=180 Len=7: 120,100,1,1,1,1,1
9999-12-31 23:59:59.999999000 Typ=180 Len=11: 199,199,12,31,24,60,60,59,154,198,24
-0001-01-01 00:00:00.000000000 Typ=180 Len=7: 100,99,1,1,1,1,1
-0100-03-04 13:02:03.234015000 Typ=180 Len=11: 99,100,3,4,14,3,4,13,242,201,24
2004-12-15 16:14:52.738000000 Typ=180 Len=11: 120,104,12,15,17,15,53,43,252,252,128
2000-01-01 00:00:00.123457000 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,232
2000-01-01 00:00:00.123456789 Typ=180 Len=11: 120,100,1,1,1,1,1,7,91,205,21
已選擇8行。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12801008/viewspace-607642/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle基本資料型別儲存格式淺析(三)——日期型別(三)Oracle資料型別
- Oracle基本資料型別儲存格式淺析(三)——日期型別(一)Oracle資料型別
- Oracle基本資料型別儲存格式淺析(三)——日期型別(四)Oracle資料型別
- Oracle基本資料型別儲存格式淺析——RAW型別Oracle資料型別
- Oracle基本資料型別儲存格式淺析(二)——數字型別Oracle資料型別
- Oracle基本資料型別儲存格式淺析(五)——RAW型別Oracle資料型別
- Oracle基本資料型別儲存格式淺析[zt]Oracle資料型別
- Oracle基本資料型別儲存格式淺析(四)——ROWID型別Oracle資料型別
- Oracle Lob型別儲存淺析Oracle型別
- Oracle Xmltype型別淺析OracleXML型別
- Oracle 儲存型別Oracle型別
- oracle資料型別與儲存結構Oracle資料型別
- 二, 基本資料型別(上)資料型別
- 三,基本資料型別(下)資料型別
- Mysql資料庫學習(二):資料型別(數值型別 日期和時間型別 字串型別)MySql資料庫資料型別字串
- MYSQL 資料型別儲存-數值型MySQL 資料型別
- oracle資料型別data type與儲存空間大小(二)Oracle資料型別
- mysql儲存日期使用什麼型別MySql型別
- ORACLE日期型別Oracle型別
- 基本資料型別與字串型別資料型別字串
- js資料型別之基本資料型別和引用資料型別JS資料型別
- 基本資料型別資料型別
- double型別資料在記憶體中中儲存格式型別記憶體
- Timestamp型別淺析型別
- redis-4.資料儲存型別Redis型別
- MYSQL-資料型別儲存-DATEMySql資料型別
- ORACLE 9I 中的日期格式型別Oracle型別
- Redis(一):基本資料型別與底層儲存結構Redis資料型別
- 【MySQL資料型別2之--日期時間型別】MySql資料型別
- 【MySQL】時間型別儲存格式選擇MySql型別
- JAVA中基本資料型別和引用資料型別Java資料型別
- 淺談oracle複合資料型別Oracle資料型別
- JavaScript基本資料型別JavaScript資料型別
- Java 基本資料型別Java資料型別
- Java基本資料型別Java資料型別
- Mysql基本資料型別MySql資料型別
- Redis基本資料型別Redis資料型別
- Java -基本資料型別Java資料型別