The common string functions of DLI are as follows:
Operator |
Returned Data Type |
Description |
---|---|---|
VARCHAR |
Concatenates two strings. |
|
INT |
Returns the number of characters in a string. |
|
INT |
Returns the number of characters in a string. |
|
VARCHAR |
Concatenates two or more string values to form a new string. If the value of any parameter is NULL, skip this parameter. |
|
VARCHAR |
Concatenates each parameter value and the separator specified by the first parameter separator to form a new string. The length and type of the new string depend on the input value. |
|
INT |
Returns the absolute value of HASH_CODE() of a string. In addition to string, int, bigint, float, and double are also supported. |
|
VARCHAR |
Returns a string whose first letter is in uppercase and the other letters in lowercase. Words are sequences of alphanumeric characters separated by non-alphanumeric characters. |
|
BOOLEAN |
Checks whether a string contains only letters. |
|
BOOLEAN |
Checks whether a string contains only digits. |
|
BOOLEAN |
Checks whether a string is numeric. |
|
BOOLEAN |
Checks whether a string is a valid URL. |
|
VARCHAR |
Obtains the value of a specified path in a JSON string. |
|
VARCHAR |
Obtains the value of a key in a key-value pair string. |
|
VARCHAR |
Returns a string of lowercase characters. |
|
VARCHAR |
Concatenates the pad string to the left of the str string until the length of the new string reaches the specified length len. |
|
VARCHAR |
Returns the MD5 value of a string. If the parameter is an empty string (that is, the parameter is "), an empty string is returned. |
|
VARCHAR |
Replaces the substring of x with y. Replace length+1 characters starting from start_position. |
|
INT |
Returns the position of the first occurrence of the target string x in the queried string y. If the target string x does not exist in the queried string y, 0 is returned. |
|
VARCHAR |
Replaces all str2 in the str1 string with str3.
|
|
VARCHAR |
Concatenates the pad string to the right of the str string until the length of the new string reaches the specified length len. |
|
STRING |
Returns the SHA1 value of the expr string. |
|
STRING |
Returns the SHA256 value of the expr string. |
|
ARRAY[STRING] |
Separates the value string as string arrays by using the delimiter. |
|
VARCHAR |
Returns the substring starting from a fixed position of A. The start position starts from 1. |
|
STRING |
Removes A at the start position, or end position, or both the start and end positions from B. By default, string expressions A at both the start and end positions are removed. |
|
VARCHAR |
Returns a string converted to uppercase characters. |
Concatenates two or more string values to form a new string. If the value of any parameter is NULL, skip this parameter.
VARCHAR CONCAT(VARCHAR var1, VARCHAR var2, ...)
SELECT CONCAT("abc", "def", "ghi", "jkl");
"abcdefghijkl"
Concatenates each parameter value and the separator specified by the first parameter separator to form a new string. The length and type of the new string depend on the input value.
If the value of separator is null, separator is combined with an empty string. If other parameters are set to null, the parameters whose values are null are skipped during combination.
VARCHAR CONCAT_WS(VARCHAR separator, VARCHAR var1, VARCHAR var2, ...)
SELECT CONCAT_WS("-", "abc", "def", "ghi", "jkl");
"abc-def-ghi-jkl"
Return the string whose first letter is in uppercase and the other letters in lowercase. Strings are sequences of alphanumeric characters separated by non-alphanumeric characters.
VARCHAR INITCAP(a)
SELECT INITCAP(var1)as aa FROM T1;
Test Data (var1) |
Test Result (aa) |
---|---|
aBCde |
Abcde |
BOOLEAN IS_ALPHA(VARCHAR content)
SELECT IS_ALPHA(content) AS case_result FROM T1;
Test Data (content) |
Test Result (case_result) |
---|---|
Abc |
true |
abc1#$ |
false |
null |
false |
Empty string |
false |
BOOLEAN IS_DIGITS(VARCHAR content)
SELECT IS_DIGITS(content) AS case_result FROM T1;
Test Data (content) |
Test Result (case_result) |
---|---|
78 |
true |
78.0 |
false |
78a |
false |
null |
false |
Empty string |
false |
This function is used to check whether a string is a numeric one.
BOOLEAN IS_NUMBER(VARCHAR content)
SELECT IS_NUMBER(content) AS case_result FROM T1;
Test Data (content) |
Test Result (case_result) |
---|---|
78 |
true |
78.0 |
true |
78a |
false |
null |
false |
Empty string |
false |
This function is used to check whether a string is a valid URL.
BOOLEAN IS_URL(VARCHAR content)
SELECT IS_URL(content) AS case_result FROM T1;
Test Data (content) |
Test Result (case_result) |
---|---|
https://www.testweb.com |
true |
https://www.testweb.com:443 |
true |
www.testweb.com:443 |
false |
null |
false |
Empty string |
false |
VARCHAR JSON_VALUE(VARCHAR content, VARCHAR path)
SELECT JSON_VALUE(content, path) AS case_result FROM T1;
Test Data (content and path) |
Test Result (case_result) |
|
---|---|---|
{ "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}} |
$ |
{ "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}} |
{ "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}} |
$.a1 |
v1 |
{ "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}} |
$.a4 |
{"a41":"v41","a42": ["v1","v2"]} |
{ "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}} |
$.a4.a42 |
["v1","v2"] |
{ "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}} |
$.a4.a42[0] |
v1 |
This function is used to obtain the value of a key in a key-value pair string.
VARCHAR KEY_VALUE(VARCHAR content, VARCHAR split1, VARCHAR split2, VARCHAR key_name)
SELECT KEY_VALUE(content, split1, split2, key_name) AS case_result FROM T1;
Test Data (content, split1, split2, and key_name) |
Test Result (case_result) |
|||
---|---|---|---|---|
k1=v1;k2=v2 |
; |
= |
k1 |
v1 |
null |
; |
= |
k1 |
null |
k1=v1;k2=v2 |
null |
= |
k1 |
null |
Concatenates the pad string to the left of the str string until the length of the new string reaches the specified length len.
VARCHAR LPAD(VARCHAR str, INT len, VARCHAR pad)
SELECT LPAD("adc", 2, "hello"), LPAD("adc", -1, "hello"), LPAD("adc", 10, "hello");
"ad",,"helloheadc"
Replaces the substring of x with y. Replaces length+1 characters starting from start_position.
VARCHAR OVERLAY ( (VARCHAR x PLACING VARCHAR y FROM INT start_position [ FOR INT length ]) )
OVERLAY('abcdefg' PLACING 'xyz' FROM 2 FOR 2) AS result FROM T1;
result |
---|
axyzdefg |
Returns the position of the first occurrence of the target string x in the queried string y. If the target string x does not exist in the queried string y, 0 is returned.
INTEGER POSITION(x IN y)
POSITION('in' IN 'chin') AS result FROM T1;
result |
---|
3 |
The string replacement function is used to replace all str2 in the str1 string with str3.
VARCHAR REPLACE(VARCHAR str1, VARCHAR str2, VARCHAR str3)
SELECT replace( "hello world hello world hello world", "world", "hello" );
"hello hello hello hello hello hello"
Concatenates the pad string to the right of the str string until the length of the new string reaches the specified length len.
VARCHAR RPAD(VARCHAR str, INT len, VARCHAR pad)
SELECT RPAD("adc", 2, "hello"), RPAD("adc", -1, "hello"), RPAD("adc", 10, "hello");
"ad",,"adchellohe"
Separates the value string as string arrays by using the delimiter.
delimiter uses the Java regular expression. If special characters are used, they need to be escaped.
ARRAY[String] STRING_TO_ARRAY(STRING value, VARCHAR delimiter)
SELECT string_to_array("127.0.0.1", "\\."), string_to_array("red-black-white-blue", "-");
[127,0,0,1],[red,black,white,blue]
Returns the substring that starts from a fixed position of A. The start position starts from 1.
The value of start starts from 1. If the value is 0, it is regarded as 1. If the value of start is a negative number, the position is calculated from the end of the string in reverse order.
VARCHAR SUBSTRING(STRING A FROM INT start)
Or
VARCHAR SUBSTRING(STRING A FROM INT start FOR INT len)
SELECT SUBSTRING("123456" FROM 2);
"23456"
SELECT SUBSTRING("123456" FROM 2 FOR 4);
"2345"
Remove A at the start position, or end position, or both the start and end positions from B. By default, string expressions A at both the start and end positions are removed.
STRING TRIM( { BOTH | LEADING | TRAILING } STRING a FROM STRING b)
SELECT TRIM(BOTH " " FROM " hello world ");
"hello world"