Equaivalent of Oracle concatenation operator in MySQL?


The concat operator can be used in ORACLE. MySQL use concat() function to perform concatenation.

To understand the concat() function, let us create a table. The query to create a table is as follows −

mysql> create table ConcatenationDemo
   −> (
   −> Id int,
   −> Name varchar(100)
   −> );
Query OK, 0 rows affected (0.86 sec)

Insert some records in the table using insert command. The query is as follows −

mysql> insert into ConcatenationDemo values(100,'John');
Query OK, 1 row affected (0.19 sec)

mysql> insert into ConcatenationDemo values(101,'Sam');
Query OK, 1 row affected (0.25 sec)

mysql> insert into ConcatenationDemo values(102,'Johnson');
Query OK, 1 row affected (0.15 sec)

mysql> insert into ConcatenationDemo values(103,'Carol');
Query OK, 1 row affected (0.26 sec)

mysql> insert into ConcatenationDemo values(104,'Bob');
Query OK, 1 row affected (0.13 sec)

Display all records from the table using select statement. The query is as follows −

mysql> select *from ConcatenationDemo;

The following is the output −

+------+---------+
| Id   | Name    |
+------+---------+
|  100 | John    |
|  101 | Sam     |
|  102 | Johnson |
|  103 | Carol   |
|  104 | Bob     |
+------+---------+
5 rows in set (0.00 sec)

Here is the query to perform concatenation in MySQL −

mysql> select concat('(',Id,',',Name,')') as ConcatIdAndName from ConcatenationDemo;

The following is the output displaying the concatenated result −

+-----------------+
| ConcatIdAndName |
+-----------------+
| (100,John)      |
| (101,Sam)       |
| (102,Johnson)   |
| (103,Carol)     |
| (104,Bob)       |
+-----------------+
5 rows in set (0.00 sec)

Updated on: 30-Jul-2019

74 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements