長度以及大小寫
SELECT
--11
length('hello world') as str_length,
-- 判斷字元串是否為空,空為1,非空為0
--0
empty('hello world'),
--1
notEmpty('hello world'),
--11
lengthUTF8('hello world'),
--11
char_length('hello world'), -- 同 lengthUTF8()
--11
character_length('hello world'), -- 同 lengthUTF8(),
--字母全部小寫(将字元串中的ASCII轉換為小寫。)
lower('abcd123--'),
--字母全部大寫(将字元串中的ASCII轉換為大寫。)
upper('abcd123--'),
lowerUTF8('abcd123-/*\8asd-\\'), -- abcd123-/*8asd-\
upperUTF8('abcd123--'), -- ABCD123--
--檢查字元串是否為有效的UTF-8編碼,是則傳回1,否則傳回0。
--clickhouse沒有布爾函數
isValidUTF8('abcd123--/*\*');
字元串拼接
SELECT concat('Hello',' ','World', '!');
+----------------------------------+
|concat('Hello', ' ', 'World', '!')|
+----------------------------------+
|Hello World! |
+----------------------------------+
字元串截取
編碼和截取有關系
SELECT
substring('abcdefg', 1, 3),-- abc
substring('你好,世界', 1, 3),-- 你
substringUTF8('你好,世界', 1, 3); -- 你好,
+--------------------------+------------------------+----------------------------+
|substring('abcdefg', 1, 3)|substring('你好,世界', 1, 3)|substringUTF8('你好,世界', 1, 3)|
+--------------------------+------------------------+----------------------------+
|abc |你 |你好, |
+--------------------------+------------------------+----------------------------+
删除空格
-- trimLeft(s) 傳回一個字元串,用于删除左側的空白字元
-- trimRight(s) 傳回一個字元串,用于删除右側的空白字元
-- trimBoth(s) 傳回一個字元串,用于删除左側和右側的空白字元
SELECT
trimLeft(' sdfdgs'), -- sdfdgs
trimRight('abcd '), -- abcd
trimBoth(' abcd '); -- abcd
判斷
-- endsWith(s, suffix) 傳回是否以指定的字尾結尾。如果字元串以指定的字尾結束,則傳回1,否則傳回0
-- startWith(s, prefix) 傳回是否以指定的字首開頭。如果字元串以指定的字首開頭,則傳回1,否則傳回0。
SELECT
endsWith('string','g'),
startsWith('string', 'str'); -- 1 true
+-----------------------+---------------------------+
|endsWith('string', 'g')|startsWith('string', 'str')|
+-----------------------+---------------------------+
|1 |1 |
+-----------------------+---------------------------+