MySQL CONCAT () concat_ws () Group_concat () connection string function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.