类型转换涉及隐式转化和显示转化
SELECT substr("abc", 2);
> bc
SELECT substr("abc", 2, 1);
> b
select INSTR ('Tech on the net', 'e')
> 2
select INSTR ('Tech on the net', 'e', 1, 1)
> 2
select INSTR ('Tech on the net', 'e', 1, 2)
>11
select INSTR ('Tech on the net', 'e', 1, 3)
>14
截取字符串中某个特定字符后的内容
ABCD_123 截取’_'后的数字
select substr('ABCD_123',instr('ABCD_123','_') + 1);
>123
截取 3_1.1.0_1 中的各部分
select substr ('3_1.1.0_1',1,instr('3_1.1.0_1','_',1,1)-1);
>3
select substr ('3_1.1.0_1',1,instr('3_1.1.0_1','_',1,2)-1);
>1.1.0
select substr('3_1.1.0_1',instr('3_1.1.0_1','_',1,2) + 1);
>1
split_part(string, separator, start[, end])
同样是截取 3_1.1.0_1 各部分,用split_part更方便
select SPLIT_PART('3_1.1.0_1','_',1)
>3
select SPLIT_PART('3_1.1.0_1','_',2)
>1.1.0
select SPLIT_PART('3_1.1.0_1','_',3)
>1
参数说明:
● A,B等为string类型,若输入为bigint, double, datetime类型会隐式转换为string后参与运算,其它类型报异常。
返回值:
string
select concat('abc', 'def','gh') ;
>abcdefgh
select concat_ws(',', 'abc', 'def', 'gh');
> abc,def,gh
SELECT concat_ws(",",passengerid,survived)
FROM train
;
SELECT wm_concat(",",passengerid)
FROM train
;
参考资料:
https://help.aliyun.com/document_detail/57792.html?spm=a2c4g.11186623.6.681.33b9a9b0FIgwyd