将字符转换为日期-配置单元

vmdwslir  于 2021-06-25  发布在  Hive
关注(0)|答案(1)|浏览(282)

我需要concat 2列字符在1列日期。我试过了:

INSERT INTO tb_teste PARTITION (dt_originacao_fcdr)
SELECT
tp_registro_fcdr,
seq_registro_fcdr,
tp_cdr_fcdr,
dt_atendimento_fcdr,
date_dt_atendimento_fcdr,
hr_atendimento_fcdr,
timestamp(from_unixtime(unix_timestamp(CONCAT(dt_atendimento_fcdr, hr_atendimento_fcdr), 'yyyyMMddHHmmss')), "yyyy-MM-dd HH:mm:ss") as date_hr_atendimento_fcdr,
duracao_atend_fcdr,
hr_originacao_fcdr,
duracao_total_fcdr,
duracao_chamada_tarifada_fcdr,
st_chamada_fcdr,
fim_sel_orig_fcdr,
numero_a_fcdr,
tp_numero_a_fcdr,
numero_b_fcdr,
tp_numero_b_fcdr,
numero_b_orig_fcdr,
numero_c_fcdr,
tp_numero_c_fcdr,
tp_trafego_fcdr,
esn_fcdr,
central_fcdr,
erb_fcdr,
tp_erb_fcdr,
face_erb_inici_fcdr,
erb_final_fcdr,
face_erb_final_fcdr,
erb_original_fcdr,
imsi_fcdr,
imei_fcdr,
tecnologia_fcdr,
cd_oper_ass_a_fcdr,
cd_oper_ass_b_fcdr,
cgi_fcdr,
nu_tlfn_fcdr,
tp_tlfn_fcdr,
tp_tarifa_fcdr,
ident_num_a_fcdr,
ident_num_b_fcdr,
cd_prestadora_fcdr,
cna_orig_ar_erb_fcdr
FROM tb_op_nor;

结果:日期:2019-03-03
包含时间和日期的列不为null或空。例子:


时区:巴西。
我需要日期和时间在同一列。

kqhtkvqz

kqhtkvqz1#

你可以 concat 那么两个领域呢 unix_timestamp 通过使用 from_unixtimestamp 函数我们可以格式化输出时间戳。

with cte as (select stack(1,"20190303","131615") as (dt,hr)) --sample data
select 
timestamp( --cast to timestamp
        from_unixtime(unix_timestamp(concat(dt,hr),'yyyyMMddHHmmss'),"yyyy-MM-dd HH:mm:ss") --concat and change the format
        ) 
from cte
``` `Output:` ```
2019-03-03 13:16:15.0

如果要将巴西时间转换为utc时间,或反之亦然,请使用to\u utc\u timestamp/from\u utc\u timestamp。

相关问题