concat SQL | concatenate in SQL - sql - sql tutorial - learn sql




 sql concat
  • String concatenation means to append one string to the end of another string.
  • SQL allows us to concatenate strings but the syntax varies according to which database system you are using.
  • Concatenation can be used to join strings from different sources including column values, literal strings, output from user defined functions or scalar sub queries etc.
  • The Concatenate function combines multiple character strings together. Each database provides its own way(s) to do this:
    1. MySQL: CONCAT( )
    2. Oracle: CONCAT( ), ||
    3. SQL Server: +

Syntax:

The syntax for CONCAT () is as follows:

CONCAT (str1, str2, str3, ...)
  • The above syntax concatenates str1, str2, str3, and any other strings together.
  • Each str can be a column name, or it can be a literal character string (meaning a sequence of characters enclosed by two single quotes), or just white space.
  • Please note the Oracle CONCAT( ) function only allows two arguments -- only two strings can be put together at a time using this function.
  • However, it is possible to concatenate more than two strings at a time in Oracle using '||'.

The syntax for using '||' to concatenate is as follows:

str1 || str2 || str3 ...

The syntax for using '+' to concatenate is as follows:

str1 + str2 + str3 ... 

Examples:

SQL concat

We use the following table for our examples.

Table Geography

Region_Name Store_Name
East Boston
East New York
West Los Angeles
West San Diego
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Example 1: Use CONCAT function to concatenate

sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

MySQL/Oracle:

SELECT CONCAT(Region_Name, Store_Name) FROM Geography 
                        WHERE Store_Name = 'New York';

Result:

'East New York'
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Example 2: Use '||' to concatenate

sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Oracle:

SELECT Region_Name || ' ' || Store_Name FROM Geography 
                     WHERE Store_Name = 'Boston';

Result:

'East Boston'
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Example 3: Use '+' to concatenate

sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

SQL Server:

SELECT Region_Name + ' ' + Store_Name FROM Geography 
                     WHERE Store_Name = 'Boston';

Result:

'East Boston'

This tutorial provides more the basic needs and informations on sql tutorial , pl sql tutorial , mysql tutorial , sql server , sqlcode , sql queries , sql , sql formatter , sql join , w3schools sql , oracle tutorial , mysql , pl sql , learn sql , sql tutorial for beginners , sql server tutorial , sql query tutorial , oracle sql tutorial , t sql tutorial , ms sql tutorial , database tutorial , sql tutorial point , oracle pl sql tutorial , oracle database tutorial , oracle tutorial for beginners , ms sql server tutorial , sql tutorial pdf

Related Searches to concat SQL | concatenate in SQL