How to use the concat function in MySQL: CONCAT(str1,str2,…) The return value is a string resulting from the concatenation of the parameters. If any parameter is NULL, the return value is NULL. Notice: If all arguments are nonbinary strings, the result is a nonbinary string. If the argument contains any binary string, the result is a binary string. A numeric argument is converted to its binary string equivalent; to avoid this, use an explicit cast, for example: SELECT CONCAT(CAST(int_col AS CHAR), char_col) MySQL's concat function can connect one or more strings, such as mysql> select concat('10'); mysql> select concat('11','22','33'); When MySQL's concat function concatenates strings, if one of them is NULL, it will return NULL mysql> select concat('11','22',null); concat_ws function in MySQL Directions: CONCAT_WS(separator,str1,str2,...) CONCAT_WS() stands for CONCAT With Separator and is a special form of CONCAT(). The first parameter is the separator for the other parameters. The delimiter is placed between the two strings to be concatenated. The separator can be a string or other parameters. Notice: If delimiter is NULL, the result is NULL. The function ignores any NULL values following the separator parameter. If the connection is separated by commas mysql> select concat_ws(',','11','22','33'); +-------------------------------+ Unlike the concat function in MySQL, the concat_ws function will not return NULL due to NULL values when executed. mysql> select concat_ws(',','11','22',NULL); MySQL group_concat function The complete syntax is as follows: group_concat([DISTINCT] Fields to be connected [Order BY ASC/DESC sorting fields] [Separator 'separator']) Basic Query mysql> select * from aa; Group by id and print the value of the name field in one line, separated by commas (default) mysql> select id,group_concat(name) from aa group by id; Group by id and print the value of the name field in one line, separated by semicolons mysql> select id,group_concat(name separator ';') from aa group by id; Group by id and print the value of the name field without redundancy in one line. Comma separated mysql> select id,group_concat(distinct name) from aa group by id; Group by id, print the value of the name field in one line, separated by commas, in descending order by name mysql> select id,group_concat(name order by name desc) from aa group by id; repeat() Function Used to copy a string. In the following example, 'ab' represents the string to be copied, and 2 represents the number of copies. mysql> select repeat('ab',2); +----------------+ 1 row in set (0.00 sec) Another example +---------------+ mysql appends a string to a field in the table: update table_name set field=CONCAT(field,'',str) mysql adds a string before a field in a table update table_name set field=CONCAT('str',field) This function may be of great help to you! ! The above article briefly talks about the concat function in MySQL and how to add a string before/after a field in MySQL. This is all the content I want to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to add interface listening mask in Vue project
>>: Nginx cache files and dynamic files automatic balancing configuration script
Original : http://developer.yahoo.com/performance...
When joining a Windows 2008 server subdomain to a...
Hello everyone, today when I was looking at the H...
Table of contents 1. React Basic Usage Notable Fe...
Table of contents Preface 1. Why do cross-domain ...
CentOS 8 is now available! CentOS 8 and RedHat En...
Table of contents JavaScript private class fields...
Table of contents 1. Brief Introduction 2. setInt...
As shown below: Mainly execute authorization comm...
Canal is an open source project under Alibaba, de...
If you already have some kind of password policy ...
<br />Since the Ministry of Foreign Affairs ...
Dividing lines are a common type of design on web...
1. Overview Users expect the web applications the...
Table of contents Overview How to achieve it Spec...