2012-12-22 24 views

回答

4

你可以使用一個TIMESTAMP類型。它存儲精度高達納秒精度的時間(默認爲微秒)。

參見Oracle Built-in Datatypes

選擇一個虛擬年份和日期:

select to_timestamp('00/01/01 01:02:03.123456', 
        'YY/MM/DD HH24:MI:SS.FF') from dual; 

或者你可以使用一個INTERVAL類型太:

SQL> create table foo (a interval day to second);  
Table created. 
SQL> insert into foo values (to_dsinterval('0 01:02:03.123456')); 
1 row created. 
SQL> select * from foo; 

A 
--------------------------------------------------------------------------- 
+00 01:02:03.123456 
+0

謝謝,但有可能只存儲時間,而不是日期?我沒有找到它如何爲前例插入一個時間值。 3:52:09(分:秒:毫秒) – user1669461

+0

實際上,間隔可能會更好。更新。 – Mat

0
1. Oracle does not store millisecond directly but it does store seconds 
    with a fraction component which can help you to get the 
    milliseconds. 
2. Not only millisecond rather you can get to microseconds too! In fact 
    you can specify the number of digits that oracle stores in the 
    fractional part of seconds i.e. the precision part for `TIMESTAMP` 
    datatype. The default is platform dependant, on UNIX it defaults to 
    6 and on windows it defaults to 3. The valid range is [0-9]. 

參見:DBA_BLOG

0

使用時間戳數據類型(你可以指定精度,如果你想)。 如果您想要存儲來自不同時區的值,請改爲使用帶timezone的時間戳。

0

我根本不會使用時間戳來存儲數據。如果分鐘,秒和毫秒的信息在存儲之前可用,我寧願創建一個包含三個數字字段的單獨表格來存儲信息;的原因,與代理鍵以及:-)