我有使用以下功能创建的以下列
to_char(to_date(f.f_sto_sta_dt_id, 'YYYYMMDD') + (f.f_sto_sta_ti_id/86400), 'YYYY-MM-DD HH24:MI:SS') as sto_sta dt_cur
T1
f_sto_sta_dt_id f_sto_sto_dt_id(number format) f_sto_sta_ti_id(number format) sto_sta_dr_cur sto_sto_dt_cur
20191001 20191001 7789 7822 02:09:49 02:10:22
我想添加2列,将sto_sta_dr_cur
和sto_sto_dt_cur
转换为UTC时间。
sto_sta_dr_cur
和sto_sto_dt_cur
的时间格式为CET
。
实现此目标的最佳方法是什么?
答案 0 :(得分:1)
Oracle设置:
CREATE TABLE test_data ( f_sto_sta_dt_id, f_sto_sto_dt_id, f_sto_sta_ti_id, f_sto_sto_ti_id ) AS
SELECT 20191001, 20191001, 7789, 7822 FROM DUAL
查询:
SELECT FROM_TZ(
TO_TIMESTAMP( TO_CHAR( f_sto_sta_dt_id ), 'YYYYMMDD' )
+ NUMTODSINTERVAL( f_sto_sta_ti_id, 'SECOND' ),
'CET'
) AT TIME ZONE 'UTC' AS sto_sta_dt_cur,
FROM_TZ(
TO_TIMESTAMP( TO_CHAR( f_sto_sto_dt_id ), 'YYYYMMDD' )
+ NUMTODSINTERVAL( f_sto_sto_ti_id, 'SECOND' ),
'CET'
) AT TIME ZONE 'UTC' AS sto_sto_dt_cur
FROM test_data
输出:
STO_STA_DT_CUR | STO_STO_DT_CUR :-------------------------------- | :-------------------------------- 2019-10-01 00:09:49.000000000 UTC | 2019-10-01 00:10:22.000000000 UTC
db <>提琴here