1. String length function char_length (str), Length (str)The Char_length () return value is the length of the string str, and the length of the unit is a character. A multibyte character counts as a single character. For one containing five two-byte character sets, the LENGTH () return value is 10, and the return value of Char_length () is 5
Select Char_length (' You are '); --2
Select LENGTH (' You are '); --6
2. Stitching function
CONCAT (str1, str2,...):
Returns the string that results from the connection parameter. If any one of the arguments is NULL, the return value is null.
CONCAT_WS (separator, str1, str2,...):
Concat_ws () represents CONCAT with Separator, which is a special form of the CONCAT (). The first parameter is the delimiter for the other parameter. The position of the delimiter is placed between the two strings to be concatenated. The delimiter can be a string, or it can be another parameter. If the delimiter is null, the result is null. The function ignores NULL values after any delimiter parameters.
3. Repeating functions
REPEAT (str, count):
Function Usage Description: Returns a string consisting of a repeating string str, the number of Str equals count. If Count <= 0, an empty string is returned. If STR or count is NULL, NULL is returned.
4. Find location Functions
Find_in_set (str, strlist)
If the string str is in the string list strlist consisting of N-strands, the return
The return value ranges from 1 to N. A list of strings is a string of self-chains that are separated by ', ' symbols. If the first argument is a constant string and the second is a type set column, the Find_in_set () function is optimized to use bit calculations. If STR is not strlist or strlist is an empty string, the return value is 0. If either parameter is NULL, the return value is null.
INSTR (STR,SUBSTR)
Returns the first occurrence of a substring of string str. This is the same as the two-parameter form of locate (), unless the order of the arguments is reversed.
LOCATE (substr, str), LOCATE (substr, str, POS):
The first syntax returns the first occurrence of the string str neutron string substr. The second syntax returns the first occurrence of the string str neutron string substr, starting at Pos. If SUBSTR is not in Str, the return value is 0.
5. Intercept function
Left (Str,len):
Returns the leftmost character of Len starting with the string str
Right (str, len):
Returns the right-most Len character starting from the string str.
SUBSTRING (str, POS), SUBSTRING (str from POS) SUBSTRING (str, POS, Len), SUBSTRING (str from POS for len):
The format without the Len parameter returns a substring from the string str, starting at position pos. The format with the Len parameter returns a substring of the same length as the Len character from the string str, starting at position pos. Use the from format as standard SQL syntax. You may also use a negative value for the POS. If so, the position of the substring starts at the POS character at the end of the string, not at the beginning of the string.
Select SUBSTRING (' ABCD ',-2); --cd
Note: SUBSTRING () is equivalent to substr ()
Substring_index (Str,delim,count)
Returns the string from string str before the delimiter Delim and Count appear. If Count is positive, it returns everything to the left of the final delimiter (starting from the left). If count is negative, it returns everything to the right of the delimiter (starting from the right).
Select Substring_index (' A,b,c ', ', ', 2)--A, B, from the beginning to the 2nd, the string
Substring_index (' A,b,c ', '. ', -2)--B,c the string starting from the bottom 2nd point
6. Uppercase and lowercase conversion functions
LCASE (str), LOWER (str) converted to lowercase
UCASE (str), UPPER (str) converted to uppercase
7. String substitution function
REPLACE (str, FROM_STR, TO_STR)
Returns the string str and all strings substituted by the string to_str from_str
Select REPLACE (' abcabc ', ' ab ', ' e '); --ecec
8. Inverse function reverse (str)
Select REVERSE (' abc '); --cba
9. Go to the space function
Select LTRIM (' abc '); --abc
Select RTRIM (' abc '); --abc
TRIM ([{BOTH | Leading | TRAILING} [REMSTR] from] str):
Returns the string str, where all remstr prefixes and/or suffixes have been deleted. If none of the classifiers both, leadin, or trailing is given, it is assumed to be both
Select TRIM (BOTH from ' a B '); --a b
10. Space string
Space (N): Returns a string consisting of N spaces
Common string Functions in MySQL