6

Other than getting the session timezone offset and database timezone offset, is there any other use/role of SESSIONTIMEZONE and DBTIMEZONE in oracle database.

What I want to know is what are the implications of changing SESSIONTIMEZONE and DBTIMEZONE values in terms of inserting/retrieving dates to/from the database.

Vivek
  • 11,938
  • 19
  • 92
  • 127
  • 2
    Have you already looked at the documentation - e.g. [here](https://docs.oracle.com/cd/E11882_01/server.112/e10729/ch4datetime.htm#i1006705) and [here](https://docs.oracle.com/cd/E11882_01/server.112/e10729/ch4datetime.htm#i1006728)? – Alex Poole Jul 27 '17 at 14:35

2 Answers2

2

Session and db time zones are used in these function.
- systimestamp timestamp in dbtimezone.
- current_timestamp timestamp in sessiontimezone.

And probably in many other places. I'm sure that change will affect dbms_scheduler.
Oracle also is using session timezone during implicit conversion from datetime without timezone to timestamp with time zone

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;
Arkadiusz Łukasiewicz
  • 6,241
  • 1
  • 11
  • 17
  • Nope, `dbtimezone` is not guaranteed to match `systimestamp`'s timezone: https://stackoverflow.com/questions/52531137/sysdate-and-dbtimezone-different-in-oracle-database. – Vadzim May 12 '20 at 01:03
2

sysdate and dbtimezone different in Oracle Database explains difference between dbtimezone, system timezone and sessiontimezone.

And here is how to sync sessiontimezone to system timezone if needed:

begin execute immediate 'alter session set time_zone = ''' || to_char(systimestamp, 'TZR') || ''''; end;
Vadzim
  • 24,954
  • 11
  • 143
  • 151