Flink sql - 内置函数

1. 常用的内置函数

2. .字符串转时间类型(TO_TIMESTAMP、TIMESTAMP和UNIX_TIMESTAMP)

2.1 使用

语法

TIMESTAMP TO_TIMESTAMP(BIGINT time)
TIMESTAMP TO_TIMESTAMP(VARCHAR date)
TIMESTAMP TO_TIMESTAMP(VARCHAR date, VARCHAR format)

使用

Flink SQL> select TO_TIMESTAMP('2022-09-05 18:51:44') ;
+----+-------------------------+
| op |                  EXPR$0 |
+----+-------------------------+
| +I | 2022-09-05 18:51:44.000 |
+----+-------------------------+
Received a total of 1 row

Flink SQL> 

*****************************************************************
Flink SQL> select TIMESTAMP '2022-09-05 18:51:44' a;
+----+---------------------+
| op |                   a |
+----+---------------------+
| +I | 2022-09-05 18:51:44 |
+----+---------------------+
Received a total of 1 row

Flink SQL> 

****************************************************************
Flink SQL> select UNIX_TIMESTAMP ('2022-09-05 18:51:44') a;
+----+----------------------+
| op |                    a |
+----+----------------------+
| +I |           1662375104 |
+----+----------------------+
Received a total of 1 row

Flink SQL> 




2.1 时间类型转字符串(DATE_FORMAT和FROM_UNIXTIME)

Flink SQL> select DATE_FORMAT('2022-09-05 18:51:44', 'yyyy-MM-dd HH:mm:ss');
+----+--------------------------------+
| op |                         EXPR$0 |
+----+--------------------------------+
| +I |            2022-09-05 18:51:44 |
+----+--------------------------------+
Received a total of 1 row

Flink SQL> 


*******************************************

将时间String  类型转化
 TO_TIMESTAMP(string1[, string2]) # 将 字符串类型的时间戳 转化为 TIMESTAMP 类型,默认解析格式为 'yyyy-MM-dd HH:mm:ss'

TO_TIMESTAMP(DATE_FORMAT(LOCALTIMESTAMP, 'yyyy-MM-dd HH:mm:ss'))  ts



TO_TIMESTAMP(string1[, string2]) # 将 字符串类型的时间戳 转化为 TIMESTAMP 类型,默认解析格式为 'yyyy-MM-dd HH:mm:ss'
select DATE_FORMAT(LOCALTIMESTAMP, 'yyyy-MM-dd HH:mm:ss');

Flink SQL> select DATE_FORMAT(LOCALTIMESTAMP, 'yyyy-MM-dd HH:mm:ss');
*************************************************************************************************************************
                                                                           SQL Query Result (Table)                                                                           
 Table program finished.                                                       Page: Last of 1                                                          Updated: 16:13:23.571 

                         EXPR$0
            2022-09-05 16:13:18




你可能感兴趣的:(Flink,sql,flink,数据库)