This topic describes the string functions that are supported by and those which are not supported by PolarDB-X.
Supported functions
PolarDB-X supports the following string functions.
Function | Description | Example |
---|---|---|
ASCII(s) | Returns the ASCII code of the first character in the s string. | Execute the following statement to return the ASCII code of the first character in
the "CustomerName" string.
|
CHAR_LENGTH(s) | Returns the number of characters in the s string. | Execute the following statement to return the number of characters in the "RUNOOB"
string.
|
CHARACTER_LENGTH(s) | Returns the number of characters in the s string. | Execute the following statement to return the number of characters in the "RUNOOB"
string.
|
CONCAT(s1,s2...sn) | Concatenates the s1 string, the s2 string, and other strings. | Execute the following statement to concatenate multiple strings.
|
CONCAT_WS(x, s1,s2...sn) | This function is a special form of CONCAT(s1,s2,...).This function concatenates the s1 string, the s2 string, and other strings. The x argument is the separator for the rest of the arguments. | Execute the following statement to concatenate multiple strings and separate the strings
with the first argument:
|
FIELD(s,s1,s2...) | Returns the position of the s string in a list of strings that include the s1 string and the s2 string. | Execute the following statement to return the position of the "c" string in the list
of strings. The string list is composed of the "a" string, the "b" string, the "c"
string, the "d" string, and the "e" string.
|
FIND_IN_SET(s1,s2) | Returns the position of the s1 substring within the s2 string. | Execute the following statement to return the position of the "c" substring within
the string that is composed of the "a", "b", "c", "d", and "e" substrings.
|
FORMAT(x,n) | Returns the number x in the '#,###.##' format.##", The function rounds the number x to n decimal places. | Execute the following statement to return 250500.5634 in the '#,###.##' format.
The following result is returned:
|
INSERT(s1,x,len,s2) | Replaces a substring of the s1 string with the s2 string. x specifies the position of the first character to replace in the s1 string. len specifies the length of the replaced substring. | Execute the following statement to replace the first six characters of the "example.com"
string with the "runoob" string.
The following result is returned:
|
LOCATE(s1,s) | Returns the position of the first occurrence of the s1 substring in the s string. |
|
LCASE(s) | Returns the s string in lowercase. | Execute the following statement to return the "RUNOOB" string in lowercase.
The following result is returned:
|
LEFT(s,n) | Returns the first n characters of the s string. | Execute the following statement to return the first two characters of the "runoob"
string.
The following result is returned:
|
LOWER(s) | Returns the s string in lowercase. | Execute the following statement to return the "RUNOOB" string in lowercase.
|
LPAD(s1,len,s2) | Left-pads the s1 string with the s2 string to a length of len characters. | Execute the following statement to left-pad the "abc" string with the "xx" string.
The following result is returned:
|
LTRIM(s) | Removes the leading space of the s string. | Execute the following statement to remove the leading space of the "RUNOOB" string.
The following result is returned:
|
MID(s,n,len) | Extracts a substring from the s string. n specifies the position of the first occurrence of the substring in the s string. len specifies the length of the substring. This function is a synonym for SUBSTRING(s,n,len). | Execute the following statement to extract a substring from the "RUNOOB" string. The
substring starts at the second character of the "RUNOOB" string and contains three
characters.
The following result is returned:
|
POSITION(s1 IN s) | Returns the position of the first occurrence of the s1 substring in the s string. | Execute the following statement to return the position of the first occurrence of
the "b" substring in the "abc" string.
The following result is returned:
|
REPEAT(s,n) | Repeats the s string n times. | Execute the following statement to repeat the "runoob" string three times.
The following result is returned:
|
REPLACE(s,s1,s2) | Replaces the s1 substring of the s string with the s2 string. | Execute the following statement to replace the "a" character in the "abc" string with
the "x" character.
The following result is returned:
|
REVERSE(s) | Reverses the characters in the s string. | Execute the following statement to reverse the characters in the "abc" string.
The following result is returned:
|
RIGHT(s,n) | Returns the last n characters of the s string. | Execute the following statement to return the last two characters of the "runoob"
string.
The following result is returned:
|
RPAD(s1,len,s2) | Right-pads the s1 string with the s2 string to a length of len characters. | Execute the following statement to right-pad the "abc" string with the "xx" string.
The following result is returned:
|
RTRIM(s) | Removes the trailing spaces of the s string. | Execute the following statement to remove the trailing spaces of the "RUNOOB" string.
The following result is returned:
|
SPACE(n) | Returns a string that consists of n spaces. | Execute the following statement to return a string that consists of 10 spaces.
|
STRCMP(s1,s2) | Compares the s1 string and the s2 string based on ASCII values. If the ASCII values of the strings are the same, the value 0 is returned. If the ASCII value of the s1 string is larger than that of the s2 string, the value 1 is returned. If the ASCII value of the s1 string is smaller than that of the s2 string, the value -1 is returned. | Execute the following statement to compare the "runoob" string and the "runoob" string
based on ASCII values.
The following result is returned:
|
SUBSTR(s, start, length) | Extracts a substring from the s string. start specifies the position of the first occurrence of the substring in the s string. length specifies the length of the substring. | Execute the following statement to extract a substring from the "RUNOOB" string. The
substring starts at the second character of the "RUNOOB" string and contains three
characters.
The following result is returned:
|
SUBSTRING(s, start, length) | Extracts a substring from the s string. start specifies the position of the first occurrence of the substring in the s string. length specifies the length of the substring. | Execute the following statement to extract a substring from the "RUNOOB" string. The
substring starts at the second character of the "RUNOOB" string and contains three
characters.
The following result is returned:
|
SUBSTRING_INDEX(s, delimiter, number) | Returns a substring of the s string. The delimiter argument specifies the delimiter
in the string.
If number is positive, the function locates the 'number'th delimiter by counting from the left and returns all characters to the left of this delimiter. If number is negative, the function locates the 'number'th delimiter by counting from the right and returns all characters to the right of this delimiter. 'number' is the absolute value of the number argument. |
|
TRIM(s) | Removes the leading spaces and trailing spaces from the s string. |
Removes the leading spaces and trailing spaces from the "RUNOOB" string.
|
UCASE(s) | Converts a string to uppercase letters. |
Execute the following statement to convert the "runoob" string to uppercase letters.
The following result is returned:
|
UPPER(s) | Converts a string to uppercase letters. |
Execute the following statement to convert the "runoob" string to uppercase letters.
The following result is returned:
|
Functions that are not supported
Compared with MySQL5.7, PolarDB-X does not support the following string functions:
Function | Description |
---|---|
LOAD_FILE() | Loads a file. |
MATCH | Performs a full-text search. |
SOUNDS LIKE | Compares strings that sound the same. |