Concat () String connection function usage in MySQL

Source: Internet
Author: User
Tags mysql query

CONCAT (STR1,STR2,...)

Returns a string resulting from a connection parameter. If any of the arguments are 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 ()) |
+------------------------------------+
| 2013-04-26 14:21:05 |
+------------------------------------+
1 row in Set (0.00 sec)


The MySQL concat function can connect one or more strings, such as

  code is as follows copy code
mysql> Select Concat (' Ten '); 
    +--------------+ 
    | concat (' 10 ') |  
    +--------------+ 
    | 10   | 
     +--------------+ 
    1 row in Set (0.00 sec)  
    
&nb sp;   mysql> Select concat (' One ', ', ', '); 
    +------------------------+  
    | concat (' One, ', ', ') | 
    +------------------------+  
    | 112233 | 
    +------------------------+ 
 & nbsp;  1 row in Set (0.00 sec)  


Concat_ws () represents CONCAT with Separator and is a special form of CONCAT (). The first parameter is the separator for the other arguments. The position of the separator is placed between the two strings to which you want to connect. The delimiter can be a string, or it can be another parameter. If the delimiter is null, the result is null. function ignores NULL values after any of the delimiter parameters.

The code is as follows Copy Code

mysql> SELECT concat_ws (', ', ' ' name ', ' Second name ', ' last Name ');

-> ' Name,second name,last name '

mysql> SELECT concat_ws (', ', ' ' name ', ' NULL ', ' last Name ');

-> ' name,last name '

The MySQL Concat_ws () does not ignore any empty strings. (All NULL is ignored, however).

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.