问题
How can we find out which TZNAME we are under in our Database? and by TZNAME I mean something like (from the list of)
select * from V$TIMEZONE_NAMES;
If we do a
select dbtimezone from dual
I get dbtimezone = -04:00
we retrieve the DBTIMEZONE which is the number representation of the timezone, but since there are many of them but in different places, we won't be able to be 100 % accurate. Example, currently we have -04:00 which can be Both EST CANADA and EST NY (or a date that doesn't involve daylights savings)
Is there any way to retrieve the actual TZNAME of the database timezone rather than the actual time?
Thank you
回答1:
We can extract the TIMEZONE_REGION from a timestamp, providing its a TIMESTAMP WITH TIMEZONE. Like so:
SQL> select extract(timezone_region from current_timestamp)
2 from dual
3 /
EXTRACT(TIMEZONE_REGIONFROMCURRENT_TIMESTAMP)
----------------------------------------------------------------
CET
SQL> alter session set time_zone='UTC';
Session altered.
SQL> select extract(timezone_region from current_timestamp)
2 from dual
3 /
EXTRACT(TIMEZONE_REGIONFROMCURRENT_TIMESTAMP)
----------------------------------------------------------------
UTC
SQL> alter session set time_zone='-04:00';
Session altered.
SQL> select extract(timezone_region from current_timestamp)
2 from dual
3 /
EXTRACT(TIMEZONE_REGIONFROMCURRENT_TIMESTAMP)
----------------------------------------------------------------
UNKNOWN
SQL>
The last result returns UNKNOWN because more than one Timezone name maps to an offset of minus four hours. There are various ways of setting the timezone name at the session level; one of those is likely to be the best way of work around this problem. Find out more.
来源:https://stackoverflow.com/questions/7814202/oracle-retrieve-by-tzname-is-it-possible