Database SQL string connection function: cancat ()

Source: Internet
Author: User

From: http://blog.sina.com.cn/s/blog_4b93170a0100biyp.html

Sometimes, we need to link the data obtained from different columns. Each database provides methods to achieve this purpose:

  • MySQL: Concat ()
  • ORACLE: Concat (), |
  • DB2: Concat (), |
  • SQL Server: +

The Concat () syntax of MySQL is as follows:

Concat (string 1, string 2, string 3 ,...):Concatenates string 1, string 2, and string 3.

Note:: Concat () of Oracle and DB2 only allows two parameters. In other words, only two strings can be connected at a time.

Syntax: Concat (arg1, arg2)
The Concat function returns the connection between two strings.
Eg: Select Concat (first_name, last_name) from T1

However, in Oracle and DB2, we can use '|' to concatenate multiple strings at a time.

Let's look at several examples. Suppose we have the following table:

Geography table

Region_name Store_name
East Boston
East New York
West Los Angeles
West San Diego

Example 1:

MySQL/Oracle:
Select Concat (region_name, store_name) from geography
Where store_name = 'boston ';

Result:

'Astboston'

Example 2:

Oracle:
Select region_name | ''| store_name from geography
Where store_name = 'boston ';

Result:

'East Boston'

Example 3:

SQL Server:
Select region_name + ''+ store_name from geography
Where store_name = 'boston ';

Result:

'East Boston'

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.