简体   繁体   English

Oracle时间戳数据类型

[英]Oracle timestamp data type

what is the different between timestamp data type without parameter and with parameter 0: 没有参数的时间戳数据类型与参数0之间有什么不同:

timestamp VS timestamp(0) timestamp VS timestamp(0)

The number in parentheses specifies the precision of fractional seconds to be stored. 括号中的数字指定要存储的小数秒的精度。 So, (0) would mean don't store any fraction of a second, and use only whole seconds. 因此, (0)意味着不存储任何一秒的分数,并且仅使用整秒。 The default value if unspecified is 6 digits after the decimal separator. 未指定的默认值是小数点分隔符后的6位数。

So an unspecified value would store a date like: 因此,未指定的值将存储如下日期:

TIMESTAMP 24-JAN-2012 08.00.05.993847 AM

And specifying (0) stores only: 并且仅指定(0)存储:

TIMESTAMP(0) 24-JAN-2012 08.00.05 AM

See Oracle documentation on data types. 请参阅有关数据类型的Oracle文档。

Quite simply the number is the precision of the timestamp, the fraction of a second held in the column: 很简单,数字是时间戳的精度,即列中保留的秒数:

SQL> create table t23
  2  (ts0 timestamp(0)
  3   , ts3 timestamp(3)
  4  , ts6 timestamp(6)
  5  )
  6  /

Table created.

SQL> insert into t23 values (systimestamp, systimestamp, systimestamp)
  2  /

1 row created.

SQL> select * from t23
  2  /

TS0
---------------------------------------------------------------------------
TS3
---------------------------------------------------------------------------
TS6
---------------------------------------------------------------------------
24-JAN-12 05.57.12 AM
24-JAN-12 05.57.12.003 AM
24-JAN-12 05.57.12.002648 AM


SQL> 

If we don't specify a precision then the timestamp defaults to six places. 如果我们没有指定精度,那么时间戳默认为六个位置。

SQL> alter table t23 add ts_def timestamp;

Table altered.

SQL> update t23      
  2  set ts_def = systimestamp
  3  /

1 row updated.

SQL> select * from t23
  2  /

TS0
---------------------------------------------------------------------------
TS3
---------------------------------------------------------------------------
TS6
---------------------------------------------------------------------------
TS_DEF
---------------------------------------------------------------------------
24-JAN-12 05.57.12 AM
24-JAN-12 05.57.12.003 AM
24-JAN-12 05.57.12.002648 AM
24-JAN-12 05.59.27.293305 AM


SQL> 

Note that I'm running on Linux so my TIMESTAMP column actually gives me precision to six places ie microseconds. 请注意,我正在Linux上运行,所以我的TIMESTAMP列实际上给了我精确到六个位置,即微秒。 This would also be the case on most (all?) flavours of Unix. 在大多数(所有?)Unix版本中也是如此。 On Windows the limit is three places ie milliseconds. 在Windows上,限制是三个位置,即毫秒。 (Is this still true of the most modern flavours of Windows - citation needed). (这仍然适用于最现代的Windows风格 - 需要引用)。

As might be expected, the documentation covers this. 正如所料,文档涵盖了这一点。 Find out more . 了解更多


"when you create timestamp(9) this gives you nanos right" “当你创建时间戳(9)时,这给了你正确的纳米”

Only if the OS supports it. 只有操作系统支持它。 As you can see, my OEL appliance does not: 如您所见,我的OEL设备没有:

SQL> alter table t23 add ts_nano timestamp(9)
  2  /

Table altered.

SQL> update t23 set ts_nano = systimestamp(9)
  2  /

1 row updated.

SQL> select * from t23
  2  /

TS0
---------------------------------------------------------------------------
TS3
---------------------------------------------------------------------------
TS6
---------------------------------------------------------------------------
TS_DEF
---------------------------------------------------------------------------
TS_NANO
---------------------------------------------------------------------------
24-JAN-12 05.57.12 AM
24-JAN-12 05.57.12.003 AM
24-JAN-12 05.57.12.002648 AM
24-JAN-12 05.59.27.293305 AM
24-JAN-12 08.28.03.990557000 AM


SQL> 

(Those trailing zeroes could be a coincidence but they aren't.) (那些尾随的零可能是巧合,但它们不是。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM