Home  >  Article  >  Database  >  How to insert a new string into a column value of a MySQL table using the INSERT() function?

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

WBOY
WBOYforward
2023-08-24 15:45:13617browse

如何使用 INSERT() 函数将新字符串插入 MySQL 表的列值中?

To do this, we need to use the column name as the first parameter of the INSERT() function, that is, at the position of the original string. The following example will demonstrate it:

Example

Suppose we want to add "/Old" to the value of the "year_of_admission" column of the "Student" table, then we need to write the 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 use WHERE clause in the above query as shown below, -

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

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

4 rows in set (0.00 sec)

The above is the detailed content of How to insert a new string into a column value of a MySQL table using the INSERT() function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete