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
After installing MySQL, you will find that the ro...
This article shares the specific code for JavaScr...
Copy code The code is as follows: <style type=...
I won't say much nonsense, let's just loo...
CSS realizes the process navigation effect. The s...
Table of contents 1. Introduction to teleport 1.1...
Table of contents 1. Customize the network to rea...
Overview of MySQL Partitioned Tables As MySQL bec...
1. Horizontal center Public code: html: <div c...
Preface: During database operation and maintenanc...
Here we introduce the knowledge about form elemen...
【SQL】SQL paging query summary The need for paging...
So-called talent (left brain and right brain) Tha...
Table of contents Question: answer: Reality: Know...
Password Mode PDO::__construct(): The server requ...