We often want to connect two or more strings for query or output when using mysql multi-field query. A string connection was found yesterday, And concat () can be achieved, I will share the solution below.
CONCAT (str1, str2 ,...)
Returns the string generated by the connection parameter. If any parameter is NULL, the return value is NULL.
For example:
Select concat (CAST (int_col as char), char_col)
Mysql query Date and Time:
The Code is as follows: |
Copy code |
Mysql> select concat (CURDATE (), '', CURTIME ()); + ------------------------------------ + | Concat (CURDATE (), '', CURTIME () | + ------------------------------------ + | 14:21:05 | + ------------------------------------ + 1 row in set (0.00 sec)
|
The MySQL concat function can connect one or more strings, such
The Code is as follows: |
Copy code |
Mysql> select concat ('10 '); + -------------- + | Concat ('10') | + -------------- + | 10 | + -------------- + 1 row in set (0.00 sec)
Mysql> select concat ('11', '22', '33 '); + ------------------------ + | Concat ('11', '22', '33') | + ------------------------ + | 1, 112233 | + ------------------------ + 1 row in set (0.00 sec) |
CONCAT_WS () represents CONCAT With Separator, which is a special form of CONCAT. The first parameter is the delimiter of other parameters. The separator is placed between the two strings to be connected. The delimiter can be a string or another parameter. If the Delimiter is NULL, the result is NULL. The function ignores the NULL value after any separator parameter.
The Code is as follows: |
Copy code |
Mysql> SELECT CONCAT_WS (',', 'First name', 'second name', 'last name '); -> 'First name, Second name, Last name' Mysql> SELECT CONCAT_WS (',', 'First name', NULL, 'last name '); -> 'First name, Last name' |
Mysql CONCAT_WS () does not ignore any null strings. (However, all NULL values are ignored ).