Oracle: Retrieve by TZNAME Is it possible?

拜拜、爱过 提交于 2019-12-13 02:47:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!