可以通过在列上应用 TRIM() 函数以及 Mysql UPDATE 语句来完成。下面的示例会更清楚地说明这一点。示例假设我们有一个表“Employee”,其前缀为“Dept.”,其中包含列“Department”的所有值如
可以通过在列上应用 TRIM() 函数以及 Mysql UPDATE 语句来完成。下面的示例会更清楚地说明这一点。
假设我们有一个表“Employee”,其前缀为“Dept.”,其中包含列“Department”的所有值如下 -
mysql> Select * from Employee;
+------+----------------+------------+----------------------+
| Id | Name | Address | Department |
+------+----------------+------------+----------------------+
| 100 | Raman | Delhi | IT Dept. |
| 101 | Mohan | Haryana | History Dept. |
| 102 | Shyam | Chandigarh | ENGLISH Dept. |
| 103 | Sukhjeet Singh | Patiala | Computer Engg. Dept. |
| 104 | Bimal Roy | Calcutta | Computer Engg. Dept. |
+------+----------------+------------+----------------------+
5 rows in set (0.01 sec)
现在,下面的查询将从“Department”列中删除前缀“Dept.”,并更新表格。
mysql> Update Employee set Department = TRIM(Trailing 'Dept.' FROM Department);
Query OK, 5 rows affected (0.10 sec)
Rows matched: 5 Changed: 5 Warnings: 0
mysql> Select * from Employee;
+------+----------------+------------+-----------------+
| Id | Name | Address | Department |
+------+----------------+------------+-----------------+
| 100 | Raman | Delhi | IT |
| 101 | Mohan | Haryana | History |
| 102 | Shyam | Chandigarh | ENGLISH |
| 103 | Sukhjeet Singh | Patiala | Computer Engg. |
| 104 | Bimal Roy | Calcutta | Computer Engg. |
+------+----------------+------------+-----------------+
5 rows in set (0.00 sec)
上面的结果集显示列值中没有前缀“Dept.”。
--结束END--
本文标题: 在MySQL中,如何从整个列的值中删除特定前缀并更新它们?
本文链接: https://lsjlt.com/news/438412.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0