Home > Database > Mysql Tutorial > 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
Release: 2023-08-24 15:45:13
forward
709 people have browsed it

如何使用 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template