【发布时间】:2020-05-12 09:01:18
【问题描述】:
除了获取会话时区偏移量和数据库时区偏移量之外,SESSIONTIMEZONE 和 DBTIMEZONE 在 oracle 数据库中是否还有其他用途/作用。
我想知道的是,更改 SESSIONTIMEZONE 和 DBTIMEZONE 值在向/从数据库中插入/检索日期方面有何影响。
【问题讨论】:
除了获取会话时区偏移量和数据库时区偏移量之外,SESSIONTIMEZONE 和 DBTIMEZONE 在 oracle 数据库中是否还有其他用途/作用。
我想知道的是,更改 SESSIONTIMEZONE 和 DBTIMEZONE 值在向/从数据库中插入/检索日期方面有何影响。
【问题讨论】:
这些函数中使用了会话和数据库时区。
- systimestamp dbtimezone 中的时间戳。
- current_timestamp sessiontimezone 中的时间戳。
而且可能在许多其他地方。我确信更改会影响 dbms_scheduler。
在从没有时区的日期时间到 timestamp with time zone 的隐式转换期间,Oracle 也在使用会话时区。
declare
with_dbtimezone TIMESTAMP WITH TIME ZONE := systimestamp; --dbtimezone
with_sesione_timezone TIMESTAMP WITH TIME ZONE := current_timestamp; --sesione_timezone
no_time_zone TIMESTAMP := with_dbtimezone; -- remmove timezone from ;
implicitit_converiosn TIMESTAMP WITH TIME ZONE := no_time_zone;
begin
dbms_output.put_line(to_char(with_dbtimezone,'YYYY-MM-DD hh24:mi:ss TZR'));
dbms_output.put_line(to_char(with_sesione_timezone,'YYYY-MM-DD hh24:mi:ss TZR'));
dbms_output.put_line(to_char(no_time_zone,'YYYY-MM-DD hh24:mi:ss TZR'));
dbms_output.put_line(to_char(implicitit_converiosn,'YYYY-MM-DD hh24:mi:ss TZR'));
end;
【讨论】:
dbtimezone 不能保证与systimestamp 的时区相匹配:stackoverflow.com/questions/52531137/…。
sysdate and dbtimezone different in Oracle Database 解释了 dbtimezone、system timezone 和 sessiontimezone 之间的区别。
如果需要,这里是如何将 sessiontimezone 同步到系统时区:
begin execute immediate 'alter session set time_zone = ''' || to_char(systimestamp, 'TZR') || ''''; end;
【讨论】: