使用CONCAT函数添加到MySQL列中的现有值?
为了理解这个概念,让我们首先创建一个演示表。
mysql> create table addToExistingValueDemo-> (
-> Instructor_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> Instructor_Name varchar(30),
-> Instructor_TechnicalSubject text
-> );
使用insert命令在表中插入一些记录。查询如下-
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('John','C,C++');mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('Carol','Java,Python');
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('Bob','MySQL,SQL Server');
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('David','DataStructure');
这是使用CONCAT函数添加到MySQL列中现有值的查询
mysql> update addToExistingValueDemo-> set Instructor_TechnicalSubject=concat(Instructor_TechnicalSubject,', Introduction To Algorithm')
-> where Instructor_Id=4;
Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录以查看新更改。查询如下-
mysql> select *from addToExistingValueDemo;
以下是输出
+---------------+-----------------+------------------------------------------+| Instructor_Id | Instructor_Name | Instructor_TechnicalSubject |
+---------------+-----------------+------------------------------------------+
| 1 | John | C,C++ |
| 2 | Carol | Java,Python |
| 3 | Bob | MySQL,SQL Server |
| 4 | David | DataStructure, Introduction To Algorithm |
+---------------+-----------------+------------------------------------------+
4 rows in set (0.00 sec)
以上是 使用CONCAT函数添加到MySQL列中的现有值? 的全部内容, 来源链接: utcz.com/z/316842.html