问题
In one of the Oracle database server it is showing "+01:00" when I fire the "Select dbtimezone from dual" does that mean in summer the clock will shift one hour ahead ?. In another server it is showing "+00:00" does that mean the database server setting is GMT ? but I am using the sysdate in oracle pl/sql. Client is saying the Aix server is on DST so would that mean the DB server will adopt the AIX server setting after clock change ? How to fix this problem.
回答1:
Answer is: It depends.
In total your database has three time zones
Your seesion time zone:
SESSIONTIMEZONE
This you can change by
ALTER SESSION SET TIME_ZONE=...
at any time. It is relevant for result ofCURRENT_DATE
LOCALTIMESTAMP
CURRENT_TIMESTAMP
It is also the target time zone when you do
CAST({TIMESTAMP/DATE without any timezone} AS TIMESTAMP WITH {LOCAL} TIME ZONE)
Default
SESSIONTIMEZONE
can be set by environment variableORA_SDTZ
or (on Windows) by registry entryHKLM\SOFTWARE\Wow6432Node\ORACLE\KEY_%ORACLE_HOME_NAME%\ORA_SDTZ
(for 32 bit Client), resp.HKLM\SOFTWARE\ORACLE\KEY_%ORACLE_HOME_NAME%\ORA_SDTZ
(for 64 bit Client).The database time zone:
DBTIMEZONE
Actually this is not so important in daily use, it is relevant only for
TIMESTAMP WITH LOCAL TIME ZONE
data type columns and defines the storage format.This is NOT the timezone of
SYSDATE
orSYSTIMESTAMP
!!!You cannot change
DBTIMEZONE
on your database if the database contains a table with aTIMESTAMP WITH LOCAL TIME ZONE
column and the column contains data. Otherwise it can be changed withALTER DATABASE SET TIME_ZONE='...';
. The change does not take effect until the database has been shut down and restarted.DBTIMEZONE
is set when database is created. If no time zone is provided while database creation then Oracle defaults to the time zone of the server's operating system.The time zone of database server's operating system:
This time zone is relevant for result of
SYSDATE
SYSTIMESTAMP
Naturally this time zone cannot be changed on database level. In case your home country uses Daylight Saving Times, this time zone may change twice a year. You can interrogate it with
SELECT TO_CHAR(SYSTIMESTAMP, 'tzr') FROM dual;
, for instance.
So, if your DB Server OS is setup properly, then you should get summer times from next week on (at least for Europe)
回答2:
In one of the Oracle database server it is showing "+01:00" when I fire the "Select dbtimezone from dual" does that mean in summer the clock will shift one hour ahead ?
It means your database timezone is +01:00
compared to UTC time zone.
From docs,
DBTIMEZONE returns the value of the database time zone. The return type is a time zone offset (a character type in the format '[+|-]TZH:TZM') or a time zone region name, depending on how the user specified the database time zone value in the most recent CREATE DATABASE or ALTER DATABASE statement.
So, database's DBTIMEZONE
inherits the timezone value from DB Server OS.
While SESSIONTIMEZONE
could be overridden at session level by an alter session statement.
For example,
ALTER SESSION SET TIME_ZONE=<timezone>;
This modifies the time zone of the TIMESTAMP WITH LOCAL TIME ZONE
.
In another server it is showing "+00:00" does that mean the database server setting is GMT ?
+00:00
can be assumed that the database time zone is set to UTC time zone.
For example,
SELECT DBTIMEZONE FROM DUAL;
DBTIME
------
+00:00
Read more from documentation.
回答3:
I resolved this issue by using the below command "Select Systimestamp at time zone 'GMT' from DUAL' This command wil always give the GMT date and time irrespective of OS time.
回答4:
Oracle Database automatically determines whether Daylight Saving Time is in effect for a specified time zone and returns the corresponding local time. Normally, date/time values are sufficient to allow Oracle Database to determine whether Daylight Saving Time is in effect for a specified time zone. The periods when Daylight Saving Time begins or ends are boundary cases. For example, in the Eastern region of the United States, the time changes from 01:59:59 a.m. to 3:00:00 a.m. when Daylight Saving Time goes into effect. The interval between 02:00:00 and 02:59:59 a.m. does not exist. Values in that interval are invalid. When Daylight Saving Time ends, the time changes from 02:00:00 a.m. to 01:00:01 a.m. Further explaination can be found here. http://docs.oracle.com/cd/E18283_01/server.112/e10729/ch4datetime.htm#insertedID11
来源:https://stackoverflow.com/questions/29271224/how-to-handle-day-light-saving-in-oracle-database