C/C++教程

oracle 的timestamp类型

本文主要是介绍oracle 的timestamp类型,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

TIMESTAMP Data Type

The TIMESTAMP data type is an extension of the DATE data type. It stores the year, month, and day of the DATE data type, plus hour, minute, and second values. This data type is useful for storing precise time values and for collecting and evaluating date information across geographic regions. Specify the TIMESTAMP data type as follows:

TIMESTAMP [(fractional_seconds_precision)] 

timestamp类型是date类型的一个扩展,date类型会存储年月日时分秒信息,timestamp类型精度更高,会存储到微秒、纳秒。

SQL> create table t (id number,col1 date,col2 timestamp,col3 timestamp(9));

Table created.

SQL> set long 10000
SQL> select dbms_metadata.get_ddl('TABLE','T','SCOTT') from dual;

DBMS_METADATA.GET_DDL('TABLE','T','SCOTT')
--------------------------------------------------------------------------------

CREATE TABLE "SCOTT"."T"
( "ID" NUMBER,
"COL1" DATE,
"COL2" TIMESTAMP (6),
"COL3" TIMESTAMP (9)
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
TABLESPACE "USERS"

SQL> insert into t values(1,sysdate,sysdate,sysdate);

1 row created.

SQL> select * from t;


ID COL1 COL2 COL3
---------- -------------------- ------------------------------ --------------------------------
1 2022-03-29 18:40:24 29-MAR-22 06.40.24.000000 PM 29-MAR-22 06.40.24.000000000 PM

可以看出,timestamp类型默认存储到微秒,指定精度timestamp(9) 时可以存储到纳秒。

SQL> select column_name,data_type,data_length,data_precision,data_scale from user_tab_cols where table_name='T';

 

 

timestamp(6), timestamp(9) 都会占用11个bytes,date占7个bytes。 

 

这篇关于oracle 的timestamp类型的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!