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'