This topic describes the string functions that PolarDB-X supports and does not support.
Supported functions
PolarDB-X supports the following string functions:
Function name | Description | Example |
ASCII(s) | Returns the ASCII code of the first character in string s. | Returns the ASCII code of the first character in the CustomerName field:
|
CHAR_LENGTH(s) | Returns the number of characters in string s. | Returns the number of characters in the string "RUNOOB":
|
CHARACTER_LENGTH(s) | Returns the number of characters in string s. | Returns the number of characters in the string "RUNOOB":
|
CONCAT(s1,s2...sn) | Concatenates multiple strings, such as s1 and s2, into a single string. | Concatenates multiple strings:
|
CONCAT_WS(x, s1,s2...sn) | Similar to the CONCAT(s1,s2,...) function, but adds x as a separator between each string. | Concatenates multiple strings and adds a separator:
|
FIELD(s,s1,s2...) | Returns the index position of string s in the string list (s1,s2,...). | Returns the position of the string "c" in the list of values:
|
FIND_IN_SET(s1,s2) | Returns the position of the first occurrence of string s1 in string s2. | Returns the position of the substring c in a string:
|
FORMAT(x,n) | Formats the number x as "#,###.##". The function rounds x to n decimal places. | Formats a number as "#,###.##":
Returns:
|
INSERT(s1,x,len,s2) | Replaces a substring of length len in string s1, starting at position x, with string s2. | Replaces the first 6 characters of the string with "runoob":
Returns:
|
LOCATE(s1,s) | Returns the starting position of s1 in string s. |
|
LCASE(s) | Converts all characters in string s to lowercase. | Converts the string "RUNOOB" to lowercase:
Returns:
|
LEFT(s,n) | Returns the first n characters of string s. | Returns the first two characters of the string "runoob":
Returns:
|
LOWER(s) | Converts all characters in string s to lowercase. | Converts the string "RUNOOB" to lowercase:
|
LPAD(s1,len,s2) | Pads the beginning of string s1 with string s2 until the string reaches the length len. | Pads the beginning of the string "abc" with the string "xx":
Returns:
|
LTRIM(s) | Removes leading spaces from string s. | Removes the leading spaces from the string " RUNOOB":
Returns:
|
MID(s,n,len) | Extracts a substring of length len from string s, starting at position n. This is a synonym for SUBSTRING(s,n,len). | Extracts 3 characters from the string "RUNOOB", starting from the second position:
Returns:
|
POSITION(s1 IN s) | Returns the starting position of s1 in string s. | Returns the position of "b" in the string "abc":
Returns:
|
REPEAT(s,n) | Repeats string s n times. | Repeats the string "runoob" three times:
Returns:
|
REPLACE(s,s1,s2) | Replaces all occurrences of string s1 in string s with string s2. | Replaces the character "a" with "x" in the string "abc":
Returns:
|
REVERSE(s) | Reverses the order of the characters in string s. | Reverses the order of the characters in the string "abc":
Returns:
|
RIGHT(s,n) | Returns the last n characters of string s. | Returns the last two characters of the string "runoob":
Returns:
|
RPAD(s1,len,s2) | Pads the end of string s1 with string s2 until the string reaches the length len. | Pads the end of the string "abc" with the string "xx":
Returns:
|
RTRIM(s) | Removes trailing spaces from string s. | Removes the trailing spaces from the string "RUNOOB ":
Returns:
|
SPACE(n) | Returns n space characters. | Returns 10 space characters:
|
STRCMP(s1,s2) | Compares strings s1 and s2. Returns 0 if s1 is equal to s2, 1 if s1 is greater than s2, and -1 if s1 is less than s2. | Compares two strings:
Returns:
|
SUBSTR(s, start, length) | Extracts a substring of length `length` from string s, starting at position `start`. | Extracts 3 characters from the string "RUNOOB", starting from the second position:
Returns:
|
SUBSTRING(s, start, length) | Extracts a substring of length `length` from string s, starting at position `start`. | Extracts 3 characters from the string "RUNOOB", starting from the second position:
Returns:
|
SUBSTRING_INDEX(s, delimiter, number) | Returns the substring of string s that follows the numberth occurrence of the separator. If number is positive, this function returns the characters that appear before the character at that position. If |
|
TRIM(s) | Removes leading and trailing spaces from string s. | Removes the leading and trailing spaces from the string " RUNOOB ":
|
UCASE(s) | Converts a string to uppercase. | Converts the string "runoob" to uppercase:
Returns:
|
UPPER(s) | Converts a string to uppercase. | Converts the string "runoob" to uppercase:
Returns:
|
Unsupported functions
PolarDB-X does not currently support the following string functions that are available in MySQL 5.7:
Function name | Description |
LOAD_FILE() | Loads a file. |
MATCH | Performs a full-text search. |
SOUNDS LIKE | Compares strings based on their sound. |