Skip to the content.

字符串常用函数

0. 略

func desc
lower(string) 转小写
upper(string) 转大写
replace(string,string,string) 将第一个字符串中的第二个字符串替换成第三个字符串
md5(string) 计算string的md5散列值,并以十六进制返回
repeat(string text, number int) 将string重复number次
to_hex(number int or bigint) 将数值转换成十六进制
reverse(str) 字符串逆序输出

1. split_part(src, DELIMITER, index)

select split_part('ABC-DEF', '-', 2);
/*
 split_part
------------
 DEF
(1 row)
*/

2. string_to_array(src, DELIMITER)

select string_to_array('i|love|you','|') ;
/*
 string_to_array
-----------------
 {i,love,you}
(1 row)
*/

3. unnest(array[‘i’,’love’,’you’])

select unnest(array['i','love','you']);
/*
 unnest
--------
 i
 love
 you
(3 rows)
*/

4. length(src); char_length(src);

select length('123123123');
select char_length('123123123');
/*
 char_length
-------------
           9
(1 row)
*/

5. substring(src from int [for int])

select substring('hello world' from 2 for 3);
select substring('hello world', 2, 3);
/*
 substring
-----------
 ell
(1 row)
*/

select substring('hello world' from 2);
select substring('hello world', 2);

/*
 substring
------------
 ello world
(1 row)
*/

6. concat(str “any” [, str “any” [, …] ]);

select concat('x','man',3);

/*
concat
--------
 xman3
(1 row)
*/

7. concat_ws(str “any” [, str “any” [, …] ]);

select concat_ws(',','x','man',3);

/*
concat_ws
-----------
 x,man,3
(1 row)
*/