我正在尝试从timestamp with time zone中提取本地时间,但是由于我刚开始使用这种数据类型,我会得到意想不到的结果。
我希望22作为下面每一行的输出。
with my_data as(
select to_timestamp_tz(ts, 'yyyy-mm-dd hh24:mi:ss tzh:tzm') as tsz
from (select '2017-12-07 22:23:24 +' || lpad(level, 2, '0') || ':00' as ts
from dual connect by level <= 10
)
)
select dbtimezone
,sessiontimezone
,tsz
,extract(hour from tsz)
from my_data;

为什么会发生这种情况,我需要做什么才能从带有时区的时间戳中提取本地时间?
发布于 2017-12-07 12:23:24
从带有时区值的日期时间提取时,返回的值以UTC为单位。
如果您想获得本地时间,可以使用TO_CHAR(tsz, 'HH24')或EXTRACT(hour from cast(tsz as timestamp))。
https://stackoverflow.com/questions/47692983
复制相似问题