1、查看函数列表
show functions;
describe function extended count;
2、数学函数
select round(3.1415926);
select round(3.1415926, 4);
select rand();
select rand(3);
select abs(-3);
select pi();
3、集合函数
select size(work_locations) from test_array;
select size(members) from test_map;
select map_keys(members) from test_map;
select map_values(members) from test_map;
select * from test_array where ARRAY_CONTAINS(work_locations, 'tianjin');
select *, sort_array(work_locations) from test_array;
4、类型转换函数
select binary('hadoop');
select cast('1' as bigint);
5、日期函数
select current_timestamp();
select current_date();
select to_date(current_timestamp());
select year('2020-01-11');
select month('2020-01-11');
select day('2020-01-11');
select quarter('2020-05-11');
select dayofmonth('2020-05-11');
select hour('2020-05-11 10:36:59');
select minute('2020-05-11 10:36:59');
select second('2020-05-11 10:36:59');
select weekofyear('2020-05-11 10:36:59');
select datediff('2022-12-31', '2019-12-31');
select date_add('2022-12-31', 5);
select date_sub('2022-12-31', 5);
6、条件函数
SELECT if (truename is NULL,'没有填写姓名',truename) from users;
SELECT isnull(truename) from users;
SELECT isnotnull(truename) from users;
SELECT nvl(truename,'无姓名') from users;
SELECT COALESCE (truename,brithday) from users;
SELECT username ,CASE username when '周杰轮' THEN '著名歌星' WHEN '张鲁依' THEN '著名演员' ELSE '未知人员' END FROM users;
SELECT truename ,CASE when truename is null then '无姓名' ELSE truename end FROM users;
SELECT truename ,NULLIF (truename,NULL) from users u ;
7、字符串函数
SELECT CONCAT(loginname,username) FROM users u ;
SELECT CONCAT_WS(',',loginname,username) from users u ;
SELECT username ,LENGTH (username) FROM users u ;
SELECT LOWER('ABC') ;
SELECT UPPER('avc') ;
SELECT TRIM(' hadoop ds ') ;
SELECT split('aaaa,bbbb,ccc',',')[0];
8、数据脱敏函数
SELECT mask_hash('hadoop');
9、其他函数
SELECT hash('aaahsdd');
SELECT CURRENT_USER();
SELECT CURRENT_DATABASE();
SELECT VERSION();
SELECT MD5('HADOOP');