In the mysql database, the three functions CONCAT () CONCAT_WS () GROUP_CONCAT () are connection strings, but there are also some differences between them. Let's talk about CONCAT (). Use CONCAT () if one character is null, all successful connections are null.
CONCAT () CONCAT_WS () GROUP_CONCAT () in MySQL connects the string functions CONCAT (), CONCAT_WS (), GROUP_CONCAT (), and the connection string CONCAT () CONCAT_WS () in the mysql database () GROUP_CONCAT () three functions are connected strings, but there are some differences between them. Let's talk about CONCAT (). Use CONCAT () if one character is null, all successful connections are null.
Recently, I encountered some pain points. All business processing is handled by MySQL functions, which makes mysql CPU usage difficult. SQL speech is also a language and includes some processing functions that connect strings, such:CONCAT (), CONCAT_WS (),GROUP_CONCAT ().The following describes how to use these functions.
1. CONCAT ()
Syntax: CONCAT (str1, str2 ,...)
There can be one or more parameters, and the returned result is a string generated 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.
The numeric parameter is converted to an equivalent binary string. To avoid this, you can use an explicit cast. For example, 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 delimiter of other parameters. The separator is located between two connected strings. The delimiter can be a string or another parameter. If the Delimiter is NULL, the result is NULL. If other parameters contain NULL, NULL is ignored.
3. GROUP_CONCAT ()
Syntax:
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] field to be connected [Order by asc/DESC sorting field] [Separator 'delimiter']) |
Separated by commas (,) by default.