Setting Database Time Zones in Oracle
This article contains several methods for setting the time zone in an Oracle database.
oracle miscconfigurationintermediate
by OracleDba
30 views
This article contains several methods for setting the time zone in an Oracle database.
12345678910111213141516171819202122
conn / as sysdba
create pluggable database pdb2
admin user pdbadmin identified by password1
file_name_convert=('/pdbseed/','/pdb2/');
set time_zone='Europe/London';
alter pluggable database pdb2 open;
create pluggable database pdb3
admin user pdbadmin identified by password1
file_name_convert=('/pdbseed/','/pdb3/');
set time_zone='-05:00';
alter pluggable database pdb3 open;
alter pluggable database pdb2 close;
drop pluggable database pdb2 including datafiles;
alter pluggable database pdb3 close;
drop pluggable database pdb3 including datafiles;12345678910111213141516171819202122232425
alter database set time_zone='Europe/London';
shutdown immediate;
startup;
select dbtimezone from dual;
DBTIMEZONE
-------------
Europe/London
SQL>
alter database set time_zone='-05:00';
shutdown immediate;
startup;
select dbtimezone from dual;
DBTIME
------
-05:00
SQL>1234567891011121314151617181920212223
alter session set time_zone='Europe/London';
select sessiontimezone from dual;
SESSIONTIMEZONE
---------------------------------------------------------------------------
Europe/London
SQL>
alter session set time_zone='-05:00';
select sessiontimezone from dual;
SESSIONTIMEZONE
---------------------------------------------------------------------------
-05:00
SQL>
alter session set time_zone=local;
alter session set time_zone=dbtimezone;123456789101112131415161718192021222324252627
set linesize 120
column london format a50
column new_york format a50
alter session set time_zone='Europe/London';
select to_timestamp_tz('2023-07-24 18:00:00', 'yyyy-mm-dd hh24:mi:ss') as london,
to_timestamp_tz('2023-07-24 18:00:00', 'yyyy-mm-dd hh24:mi:ss') at time zone 'America/New_York' as new_york
from dual;
LONDON NEW_YORK
-------------------------------------------------- --------------------------------------------------
24-JUL-23 06.00.00.000000000 PM EUROPE/LONDON 24-JUL-23 01.00.00.000000000 PM AMERICA/NEW_YORK
SQL>
column local format a50
select to_timestamp_tz('2023-07-24 18:00:00', 'yyyy-mm-dd hh24:mi:ss') as london,
to_timestamp_tz('2023-07-24 18:00:00', 'yyyy-mm-dd hh24:mi:ss') at local as local
from dual;
LONDON LOCAL
-------------------------------------------------- --------------------------------------------------
24-JUL-23 06.00.00.000000000 PM EUROPE/LONDON 24-JUL-23 06.00.00.000000000 PM EUROPE/LONDON
SQL>1234567891011
# UNIX/Linux
export ORA_SDTZ='Europe/London'
export ORA_SDTZ='-05:00'
export ORA_SDTZ='OS_TZ'
export ORA_SDTZ='DB_TZ'
Rem Windows
set ORA_SDTZ='Europe/London'
set ORA_SDTZ='-05:00'
set ORA_SDTZ='OS_TZ'
set ORA_SDTZ='DB_TZ'Please to add comments
No comments yet. Be the first to comment!