Connection string function of CONCAT () CONCAT_WS () GROUP_CONCAT () in MySQL

Source: Internet
Author: User
Tags mysql functions

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.

 

 

 

Related Article

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.