TO_TIMESTAMP_NTZ 函数

to_timestamp_ntz(expr [, fmt])

功能描述

TO_TIMESTAMP_NTZ 函数用于将不同类型的日期时间表达式(expr)转换为时间戳(timestamp_ntz)类型。如果提供了 fmt 参数,函数将根据指定的格式进行解析;若未提供 fmt,则按照默认格式进行转换。如果 expr 中的日期时间格式不正确,函数将返回 null。

参数说明

  • expr (string): 需要转换的字符串表达式。
  • fmt (string, 可选): 指定字符串表达式中日期时间的格式。

返回结果

转换后的时间戳(timestamp_ntz)。

案例

  1. 根据指定的格式将字符串转换为时间戳:

SELECT to_timestamp_ntz('2022/02/01 10:23:32.121', 'yyyy/MM/dd HH:mm:ss.SSS') as ntz; +-------------------------+ | ntz | +-------------------------+ | 2022-02-01 10:23:32.121 | +-------------------------+

  1. 如果字符串符合时间格式
    yyyy-MM-dd HH:mm:ss.SSS
    yyyy-MM-dd HH:mm:ss.SSS
    ,则无需指定格式参数。

SELECT to_timestamp_ntz('2022-02-01 10:23:32.121') ntz; +-------------------------+ | ntz | +-------------------------+ | 2022-02-01 10:23:32.121 | +-------------------------+

  1. 将不同类型的日期时间字符串转换为时间戳:

SELECT to_timestamp_ntz('01-02 10:23:32', 'dd-MM HH:mm:ss') ntz; +---------------------+ | ntz | +---------------------+ | 1970-02-01 10:23:32 | +---------------------+

联系我们
预约咨询
微信咨询
电话咨询