oracle 时间戳和时区相关概念

时间戳的概念:它是一种bai时间表示方式,定义du为从格林威治时间1970年zhi01月01日00时00分00秒(北京时间dao1970年01月01日08时00分00秒)起至现在的总秒数。

时间戳是一个相对于0时区的时间;

日期时间是一个相对于时区的时间戳。

DBTIMEZONE:是数据库bai服务器所在的时区。
SESSIONTIMEZONE :是你的会du话的时区。


例如:数据库服务器是放在zhi英国dao(+00:00时区),而你在中国(+08:00)访问数据库,则SESSIONTIMEZONE 就是+08:00,DBTIMEZONE就是+00:00

db是数据库的,session是针对当前会话的,因为时区在会话级可以改变

1.Oracle中时间相关的类型

时间相关的类型主要有四种:DATE,TIMESTAMP,TIMESTAMP WITH TIME ZONE,TIMESTAMP WITH LOCAL TIME ZONE。
DATE:存储日期和时间信息,精确到秒。
TIMESTAMP:DATE类型的扩展,保留小数级别的秒(默认为小数点后6位),不保存时区和地区信息。
TIMESTAMP WITH TIME ZONE:TIMESTAMP类型的一种扩展,存储时区信息。
TIMESTAMP WITH LOCAL TIME ZONE:TIMESTAMP类型的另一种扩展,用于存储一个转换为数据库设置的本地时区的时间戳。与TIMESTAMP WITH TIME ZONE类型的区别在于:数据库不保存时区相关信息,而是把客户端输入的时间转换为基于数据库时区的时间进行存储。

select dbtimezone from dual;

select sysdate from dual;

select (sysdate - to_date('1970-1-1 8','YYYY-MM-DD HH24')) * 86400 from dual;

select systimestamp from dual;

select sessiontimezone from dual;

2.Oracle中时区/时间相关的函数
DBTIMEZONE:返回数据库时区
(Returns the value of the database time zone. The value is a time zone offset or a time zone region name)
SESSIONTIMEZONE: 返回当前会话的时区
(Returns the value of the current session's time zone)
SYSDATE:返回数据库所在操作系统的时间,类型为Date(
Returns the date and time of the operating system on which the database resides, taking into account the time zone of the database server's operating system that was in effect when the database was started.)
CURRENT_DATE: 返回基于当前会话时区的时间,类型为Date
(Returns the current date in the session time zone in a value in the Gregorian calendar, of the DATE datatype.)
SYSTIMESTAMP:返回数据库所在操作系统时间,类型为TIMESTAMP WITH TIME ZONE 
(Returns the system date, including fractional seconds and time zone of the system on which the database resides.)
CURRENT_TIMESTAMP:返回基于当前会话时区的时间,类型为TIMESTAMP WITH TIME ZONE
(Returns the current date and time in the session time zone as a TIMESTAMP WITH TIME ZONE value)

猜你喜欢

转载自blog.csdn.net/aganliang/article/details/107782247