- 类别:
半结构化和结构化数据函数 (类型转换)
AS_TIMESTAMP_*¶
将 VARIANT 值转换为相应的 TIMESTAMP 值:
AS_TIMESTAMP_LTZ (具有本地时区的值)
AS_TIMESTAMP_NTZ (不带时区的值)
AS_TIMESTAMP_TZ (带时区的值)
语法¶
AS_TIMESTAMP_LTZ( <variant_expr> )
AS_TIMESTAMP_NTZ( <variant_expr> )
AS_TIMESTAMP_TZ( <variant_expr> )
实参¶
variant_expr
VARIANT 类型值计算的表达式。
示例¶
这显示了该函数的使用方法:
创建表和数据:
CREATE TABLE multiple_types ( binary1 VARIANT, date1 VARIANT, decimal1 VARIANT, time1 VARIANT, timestamp1 VARIANT ); INSERT INTO multiple_types (binary1, date1, decimal1, time1, timestamp1) SELECT TO_VARIANT(TO_BINARY('F0A5')), TO_VARIANT(TO_DATE('2018-10-10')), TO_VARIANT(TO_DECIMAL(1.23, 6, 3)), TO_VARIANT(TO_TIME('12:34:56')), TO_VARIANT(TO_TIMESTAMP_NTZ('2018-10-10 12:34:56')) ;现在运行查询:
SELECT AS_TIMESTAMP_NTZ(timestamp1) AS "Timestamp" FROM multiple_types;输出:
+-------------------------+ | Timestamp | |-------------------------| | 2018-10-10 12:34:56.000 | +-------------------------+