How can we use INSERT() function to insert a new string into the value of a column of MySQL table?


For this purpose, We need to use the name of the column as the first parameter i.e. at the place of an original string, of the INSERT() function. Following example will exhibit it −

Example

Suppose we want to add ‘/Old’ with the values of ‘year_of_admission’ column of ‘Student’ table then we need to write following query −

mysql> Select INSERT(year_of_admission,5,0,'/Old')As 'Old Admissions' From Student;

+-----------------+
| Old Admissions  |
+-----------------+
| 2001/Old        |
| 2010/Old        |
| 2009/Old        |
| 2017/Old        |
| 2000/Old        |
+-----------------+

5 rows in set (0.00 sec)

We can also apply WHERE clause, as follows, in the above query −

mysql> Select INSERT(year_of_admission,5,0,'/Old')As 'Old Admissions' From Student WHERE year_of_admission < '2017';

+----------------+
| Old Admissions |
+----------------+
| 2001/Old       |
| 2010/Old       |
| 2009/Old       |
| 2000/Old       |
+----------------+

4 rows in set (0.00 sec)

Updated on: 06-Feb-2020

108 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements