Oracle 11g并以毫秒精度存储时间

时间:2012-12-22 13:05:58

标签: oracle oracle11g

我想创建一个包含moto GP统计数据的数据库,我希望从最快圈数和其他时间存储时间。我需要存储像分钟这样的时间:秒:毫秒......我怎么能这样做?

谢谢

4 个答案:

答案 0 :(得分: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

答案 1 :(得分: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

答案 2 :(得分:0)

使用时间戳数据类型(如果需要,可以指定准确度)。 如果要存储来自不同时区的值,请改为使用带时区的时间戳。

答案 3 :(得分:0)

我根本不会使用时间戳来存储数据。如果在存储之前可以获得分钟,秒和毫秒的信息,我宁愿创建一个单独的表,其中包含三个数字字段以保存信息;原因,也有代理键: - )