String Functions
This section describes string functions, including their syntax, parameters, and usage examples.
Function List
Function |
Description |
---|---|
Pads the beginning of a string with specified characters until it reaches the specified length, and then returns the result string. If you do not specify padding characters, space characters are used for padding. |
|
Pads the end of a string with specified characters until it reaches the specified length, and then returns the result string. If you do not specify padding characters, space characters are used for padding. |
|
Replaces all occurrences of a matched substring in the original string with a specified string. If no replacement string is specified, all matched substrings are removed from the original string. |
|
Reverses the order of characters in a string. |
|
Repeats a string a specified number of times. |
|
Checks whether a string contains a specified substring. |
|
Checks whether a string contains a specified substring, regardless of letter case. |
|
Concatenates two strings and returns the concatenated result. |
|
Removes spaces from both sides of a string. |
|
Converts a string to a long integer using a specified radix (base). If no radix is provided, the default radix of 10 (decimal) is used. |
|
Splits a string using a specified delimiter and returns an array of substrings. You can set limit to limit the number of resulting substrings. |
|
Splits a string using a specified delimiter and returns the substring at a specified position. If the position exceeds the array length, an empty string is returned. |
|
Splits a string using the first delimiter, then splits the string further using the second delimiter, and returns the result. |
|
Returns a string formatted using Java's String.format method. |
|
Returns the position of the first occurrence of the target substring in a string. It returns 0 if the target substring is not found. |
|
Extracts a substring based on the start position and length. If the length is not specified, it returns the entire string starting from the start position. It is equivalent to the substring function. |
|
Extracts a substring based on the start position and length. If the length is not specified, it returns the entire string starting from the start position. |
|
Returns the length of the input characters (for a string expression) or the byte length (for a non-string expression). The byte length is at least the smallest integer obtained by dividing the number of digits by 8. |
|
Returns the length of the input characters (for a string expression) or the byte length (for a non-string expression). The byte length is at least the smallest integer obtained by dividing the number of digits by 8. This function is equivalent to the length function. |
|
Equivalent to the length function. |
|
Equivalent to the length function. |
|
Calculates the minimum edit distance between strings str1 and str2. |
|
Formats a string. |
|
Converts a string to the UTF-8 encoding format. |
|
Converts an ASCII value to characters. |
|
Concatenates multiple parameters into a string. |
lpad
This function pads the beginning of a string with specified characters until it reaches the specified length, and then returns the result string. If you do not specify padding characters, space characters are used for padding.
Syntax: lpad(str, len, lpadStr)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
len |
Length of the result string.
|
Integer |
Yes |
lpadStr |
Padding characters. |
String |
No |
Return value type: string
Example: SELECT LPAD('hello world', 10), LPAD('hello', 10, 'e')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
LPAD('hello world', 10) |
hello worl |
Scenario 2 |
LPAD('hello', 10, 'e') |
eeeeehello |
rpad
This function pads the end of a string with specified characters until it reaches the specified length, and then returns the result string. If you do not specify padding characters, space characters are used for padding.
Syntax: rpad(str, len, rpadStr)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
len |
Length of the result string.
|
Integer |
Yes |
rpadStr |
Padding characters. |
String |
No |
Return value type: string
Example: SELECT RPAD('hello world', 10), RPAD('hello', 10, 'e')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
RPAD('hello world', 10) |
hello worl |
Scenario 2 |
RPAD('hello', 10, 'e') |
helloeeeee |
replace
This function replaces all occurrences of a matched substring in the original string with a specified string. If no replacement string is specified, all matched substrings are removed from the original string.
Syntax: replace(str, subStr, replaceStr)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
subStr |
Target substring. |
String |
Yes |
replaceStr |
String for replacement. |
String |
No |
Return value type: string
Example: SELECT REPLACE('hello world', 'o'), REPLACE('hello world', 'w', 'new w')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
REPLACE('hello world', 'o') |
hell wrld |
Scenario 2 |
REPLACE('hello world', 'w', 'new w') |
hello new world |
reverse
This function reverses the order of characters in a string.
Syntax: reverse(str)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
Return value type: string
Example: SELECT REVERSE('hello world')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
REVERSE('hello world') |
dlrow olleh |
repeat
This function repeats a string a specified number of times.
Syntax: repeat(str, num)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
num |
Number of repetitions. |
Integer |
Yes |
Return value type: string
Example: SELECT REPEAT('hello world', 2), REPEAT('hello world', 0)
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
REPEAT('hello world', 2) |
hello worldhello world |
Scenario 2 |
REPEAT('hello world', 0) |
contains_string
This function checks whether a string contains a specified substring.
Syntax: contains_string(str, containsStr)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
containsStr |
Specified string. |
String |
Yes |
Return value type: Boolean
Example: SELECT CONTAINS_STRING('hello world', 'llo')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
CONTAINS_STRING('hello world', 'llo') |
true |
icontains_string
This function checks whether a string contains a specified substring, regardless of letter case.
Syntax: icontains_string(str, containsStr)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
containsStr |
Specified string. |
String |
Yes |
Return value type: Boolean
Example: SELECT ICONTAINS_STRING('hello world', 'llo')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
ICONTAINS_STRING('hello world', 'llo') |
true |
textcat
This function concatenates two strings and returns the concatenated result.
Syntax: textcat(str1, str2)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str1 |
String 1 to be concatenated. |
String |
Yes |
str2 |
String 2 to be concatenated. |
String |
Yes |
Return value type: string
Example: SELECT TEXTCAT('hello ', 'world')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
TEXTCAT('hello ', 'world') |
hello world |
btrim
This function removes spaces from both sides of a string.
Syntax: btrim(str)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
Return value type: string
Example: SELECT BTRIM(' hello world ')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
BTRIM(' hello world ') |
hello world |
parse_long
This function converts a string to a long integer using a specified radix (base). If no radix is provided, the default radix of 10 (decimal) is used.
Syntax: parse_long(str, radix)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
radix |
Base. |
Integer |
No |
Return value type: long
Example: SELECT PARSE_LONG('-1234', 8), PARSE_LONG('1234')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
PARSE_LONG('-1234', 8) |
-668 |
Scenario 2 |
PARSE_LONG('1234') |
1234 |
split
This function splits a string using a specified delimiter and returns an array of substrings. You can set limit to limit the number of resulting substrings.
Syntax: split(str, splitStr, limit)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
splitStr |
Delimiter. |
String |
Yes |
limit |
Base. |
Integer |
No |
Return value type: ARRAYS<STRING>
Example: SELECT SPLIT('helloworld', 'o'), SPLIT('helloworld', 'o', 2)
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
SPLIT('helloworld','o' ) |
["hell","w","rld"] |
Scenario 2 |
SPLIT('helloworld', 'o', 2) |
["hell","world"] |
split_part
This function splits a string using a specified delimiter and returns the substring at a specified position. If the position exceeds the array length, an empty string is returned.
Syntax: split_part(str, splitStr, position)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
splitStr |
Delimiter. |
String |
Yes |
position |
Position of the string to be returned. |
Integer |
Yes |
Return value type: string
Example: SELECT SPLIT_PART('helloworld', 'o', 2), SPLIT_PART('helloworld', 'o', 4)
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
SPLIT_PART('helloworld','o', 2) |
w |
Scenario 2 |
SPLIT_PART('helloworld', 'o', 4) |
split_to_map
This function splits a string using the first delimiter, then splits the string further using the second delimiter, and returns the result.
Syntax: split_to_map(str, splitStr1, splitStr2)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
splitStr1 |
Delimiter 1. |
String |
Yes |
splitStr2 |
Delimiter 2. |
String |
Yes |
Return value type: array
Example: SELECT SPLIT_TO_MAP('upstream_response_time:123, request_time:456', ',', ':')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
SPLIT_TO_MAP('upstream_response_time:123, request_time:456', ',', ':') |
{" request_time":"456","upstream_response_time":"123"} |
string_format
This function returns a string formatted using Java's String.format method.
Syntax: string_format(str, Object... args)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
args |
Output time format. |
String/Integer/Long/Boolean/Double |
Yes |
Return value type: string
Example: SELECT STRING_FORMAT('My name is %s and I am %d years old.', 'name', age)
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
STRING_FORMAT('My name is %s and I am %d years old.', 'Tom', 25) |
My name is Tom and I am 25 years old. |
- %d: outputs an integer.
- %f: outputs a floating point number.
- %s: outputs a string.
- %n: outputs a newline character.
- %c: outputs characters.
- %b: outputs the Boolean type.
- %e: outputs the exponential type.
- %tc: outputs date and time information.
- %tF: The output format is YYYY-MM-DD.
- %tr: The output format is HH:MM:SS PM.
strpos
This function returns the position of the first occurrence of the target substring in a string. It returns 0 if the target substring is not found.
Syntax: strpos(str, subStr)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
subStr |
Target substring. |
String |
Yes |
Return value type: integer
Example: SELECT STRPOS('hello world', 'llo'), STRPOS('llo', 'hello world')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
STRPOS('hello world', 'llo') |
3 |
Scenario 2 |
STRPOS('llo', 'hello world') |
0 |
substr
This function extracts a substring based on the start position and length. If the length is not specified, it returns the entire string starting from the start position. It is equivalent to the substring function.
Syntax: substr(str, start, length)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
start |
Start position of the target substring to be returned. |
Integer |
Yes |
length |
Length of the substring. |
Integer |
No |
Return value type: string
Example: SELECT SUBSTR('helloworld', 5), SUBSTR('helloworld', 5, 3)
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
SUBSTR ('helloworld', 5) |
oworld |
Scenario 2 |
SUBSTR ('helloworld', 5, 3) |
owo |
substring
This function extracts a substring based on the start position and length. If the length is not specified, it returns the entire string starting from the start position.
Syntax: substring(str, start, length)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
start |
Start position for extracting the substring. Valid values start from 1. |
Integer |
Yes |
length |
Length of the substring. |
Integer |
No |
Return value type: string
Example: SELECT SUBSTRING('helloworld', 5), SUBSTRING('helloworld', 5, 3)
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
SUBSTRING('helloworld', 5) |
oworld |
Scenario 2 |
SUBSTRING('helloworld', 5, 3) |
owo |
length
This function returns the length of the input characters (for a string expression) or the byte length (for a non-string expression). The byte length is at least the smallest integer obtained by dividing the number of digits by 8.
Syntax: length(str)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
Return value type: integer
Example: SELECT LENGTH('HELLO WORLD')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
LENGTH('HELLO WORLD') |
11 |
char_length
This function returns the length of the input characters (for a string expression) or the byte length (for a non-string expression). The byte length is at least the smallest integer obtained by dividing the number of digits by 8. This function is equivalent to the length function.
Syntax: char_length(str)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
Return value type: integer
Example: SELECT CHAR_LENGTH('HELLO WORLD')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
CHAR_LENGTH('HELLO WORLD') |
11 |
character_length
This function is equivalent to the length function.
Syntax: character_length(str)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
Return value type: integer
Example: SELECT CHARACTER_LENGTH('HELLO WORLD')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
CHARACTER_LENGTH('HELLO WORLD') |
11 |
strlen
This function is equivalent to the length function.
Syntax: strlen(str)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
Return value type: integer
Example: SELECT STRLEN('HELLO WORLD')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
STRLEN('HELLO WORLD') |
11 |
levenshtein_distance
This function calculates the minimum edit distance between strings str1 and str2.
Syntax: levenshtein_distance(str1, str2)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str1 |
Original string 1. |
String |
Yes |
str2 |
Original string 2. |
String |
Yes |
Return value type: integer
Example: SELECT LEVENSHTEIN_DISTANCE('horse', 'ros')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
LEVENSHTEIN_DISTANCE('horse', 'ros') |
3 |
normalize
This function formats a string (str).
- Formats str using the NFC form.
Syntax: normalize(str)
- Formats str using a specified form. The supported forms include NFC, NFD, NFKC, and NFKD.
Syntax: normalize(str, form)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str |
Original string. |
String |
Yes |
form |
Formatting form. |
String |
No |
Return value type: string
Example: SELECT NORMALIZE('schön'), NORMALIZE('Henry \u2163', 'nfd')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario 1 |
NORMALIZE('schön') |
schön |
Scenario 2 |
NORMALIZE('Henry \u2163', 'nfd') |
Henry IV |
to_utf8
This function converts a string to the UTF-8 encoding format.
Syntax: to_utf8(str)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
str1 |
Original string 1. |
String |
Yes |
str2 |
Original string 2. |
String |
Yes |
Return value type: integer
Example: SELECT TO_UTF8('%')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
TO_UTF8('%') |
JQ== |
chr
This function converts an ASCII value to characters.
Syntax: chr(ascii)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
ascii |
ASCII code. |
Integer |
Yes |
Return value type: string
Example: SELECT CHR(99)
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
CHR(99) |
c |
concat
This function concatenates multiple parameters into a string.
Syntax: concat(x, y...)
Parameter |
Description |
Type |
Mandatory |
---|---|---|---|
x,y... |
Original field. |
String |
Yes |
Return value type: string
Example: select concat('1','+','1')
Type |
Query Statement |
Returned Result |
---|---|---|
Scenario |
concat('1','+','1') |
1+1 |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.