Article directory
1. Detailed explanation of string functions
1.
The return value of ascii(str) is the value of the leftmost character of the string str, that is, the ascii code of the leftmost character is obtained. If str is an empty string, the return value is 0. If str is null, the return value is null.
2. bin(n)
returns the string representation of the binary value of n, that is, converted to binary. Where n is a longlong (bigint) number. This is equivalent to conv(n,10,2). If n is null, the return value is null.
3. bit_length(str)
returns the length of the binary string str.
4. char(n,... [using charset])
char() understands each parameter n as an integer, and its return value is a string containing the characters given by the code values of these integers. Null values are omitted. That is, all parameters are converted into characters and connected together.
5.
The return value of char_length(str) is the length of the string str, and the unit of the length is characters.
6. concat (str1, str2, ...)
returns the string generated by the connection parameters.
7. concat_ws(separator,str1,str2,…)
concat_ws() stands for concat with separator, which is a special form of concat(). The first parameter is the delimiter for other parameters. The position of the delimiter is placed between the two strings to be concatenated. The delimiter can be a string or other parameters. If the delimiter is null, the result is null. The function ignores null values after any delimiter parameter.
8. elt(n,str1,str2,str3,…)
If n=1, the return value is str1; if n=2, the return value is str2, and so on. If n is less than 1 or greater than the number of parameters, the return value is null.
9. field(str,str1,str2,str3,…)
returns the index (position) of str in the list of str1, str2, str3,…. In the case where str cannot be found, the return value is 0. If all arguments to field() are strings, all arguments are compared as strings. If all arguments are numbers, compare numbers. Otherwise, the arguments are compared as doubles.
10. find_in_set(str, strlist)
If the string str is in the string list strlist composed of n sub-chains, the range of the return value is between 1 and n (that is, the position of str in strlist). A list of strings is a string of self-links separated by ',' symbols.
11. insert(str, pos, len, newstr)
returns the string str, whose substring starts at the pos position and the len characters replaced by the string newstr for a long time.
If pos exceeds the string length, the return value is the original string. If the length of len is greater than the length of other strings, the replacement starts from position pos. If any parameter is null, the return value is null.
12. instr (str, substr)
returns the first occurrence of the substring in the string str. This is the same as the two-argument form of locate(), except that the order of the arguments is reversed.
13. lcase(str)
lcase() is a synonym for lower().
14. left(str, len)
returns the len leftmost characters starting from the string str.
15. length(str)
returns the length of the string str, in bytes. A multibyte character counts as multibyte.
16. load_file(file_name)
reads the file and returns the file in string format.
17. locate(substr, str), locate(substr, str, pos)
The first syntax returns the first occurrence position of the substring substr in the string str.
The second syntax returns the position of the first occurrence of the substring substr in the string str, starting at pos. If substr is not in str, the return value is 0.
18. lower(str)
returns the string str and all the characters changed to lowercase letters according to the latest character set mapping table.
19. lpad(str, len, padstr)
returns the string str, whose left side is filled to the length of len characters by the string padstr. If the length of str is greater than len, the return value is shortened to len characters. That is, padstr with a length of len is added in front of str.
20. ltrim(str)
returns the string str, whose leading space characters are deleted.
21. mid(str, pos, len)
mid(str, pos, len) is a synonym for substring(str, pos, len), which intercepts the string function.
22. octet_length(str)
octet_length() is a synonym for length().
23. position (substr in str)
position (substr in str) is a synonym for locate (substr, str).
24. repeat(str, count)
returns a string consisting of repeated strings str, and the number of strings str is equal to count.
If count <= 0, an empty string is returned. If str or count is null, returns null.
25. replace(str, from_str, to_str)
returns the string str and all the string from_str replaced by the string to_str.
26. reverse(str)
returns the string str, the order and character order are reversed.
27. right(str, len)
starts from the string str and returns the rightmost len characters.
28. rpad(str, len, padstr)
returns the string str, whose right side is filled to the length of len characters by the string padstr.
If the length of the string str is greater than len, the return value is shortened to the same length as len characters.
29. rtrim(str)
returns the string str, and the trailing space character is deleted.
30. soundex(str)
returns a soundex string from str.
31. space(n)
returns a string consisting of n interval symbols.
32.
The usage of substring(str, pos) is as follows:
substring(str from pos)
substring(str, pos, len)
substring(str from pos for len)
substr() is a synonym for substring().
Format without a len argument returns a substring from the string str, starting at position pos. Format with a len argument returns a substring of length len characters from the string str, starting at position pos. The format of using from is standard sql syntax. It is also possible to use a negative value for 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.
33. substring_index (str, delim, count)
returns the string from the string str before the delimiter delim and count appear. If count is positive, everything to the left of the final delimiter (starting from the left) is returned. If count is negative, everything to the right of the delimiter (starting from the right) is returned.
34. trim([{both | leading | trailing} [remstr] from] str) trim(remstr from] str)
returns the string str with all remstr prefixes and/or suffixes removed. If none of the classifiers both, leadin, or trailing is given, then both is assumed. remstr is optional, and spaces can be removed if not specified.
35. ucase(str)
ucase() is a synonym for upper().
36. upper(str)
returns the string str and the characters converted to uppercase letters according to the latest character set mapping.
37. Pattern matching
Wildcard
%: Match any number of characters, even including zero characters
_: Only match one kind of character,
escape with "/
38. strcmp(expr1, expr2)
If all the strings are the same, return 0, If the first parameter is smaller than the second according to the current sorting order, -1 is returned, otherwise 1 is returned.
2. Document download address
Word document download: Mysql database commonly used string functions