Recently encountered some egg pain, all the business processing to the MySQL function to deal with, resulting in the MySQL CPU usage is a tiger. SQL speech is also a language, including some processing functions for connection strings, such as CONCAT (), concat_ws () , Group_concat (). Let's talk about the use of these several functions.
1. CONCAT ()
Syntax: CONCAT (STR1,STR2,...)
can have one or more parameters, and the result returned is a string produced by the connection parameter.
If all parameters are non binary strings, the result is a non binary string.
If the parameter contains any binary string, the result is a binary string.
Numeric parameters are converted to binary strings that are equal to them, and you can use explicit type cast if you want to avoid this situation. such as: SELECT CONCAT (CAST (Int_col as CHAR), Char_col);
If the parameter contains null, the result is null.
2. CONCAT_WS ()
Syntax: Concat_ws (SEPARATOR,STR1,STR2,...)
The first parameter is the separator for the other arguments. The position of the separator is between the two strings connected. The delimiter can be a string, or it can be another parameter. If the delimiter is null, the result is null. If the other parameter contains NULL, the null is ignored.
3. Group_concat ()
Grammar:
Group_concat ([DISTINCT] expr [, expr ...]
[ORDER BY {Unsigned_integer | col_name | expr}
[ASC | DESC] [, col_name ...]]
[SEPARATOR Str_val])
| The code is as follows |
Copy Code |
Group_concat ([DISTINCT] The field to connect [order by Asc/desc sort field] [Separator ' delimiter]] |
The default is ', ' delimited.