如何删除mysql表中的数字字符?

前端之家收集整理的这篇文章主要介绍了如何删除mysql表中的数字字符?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在MySQL中有一个名为“Actress”的表.
我想从列“名称”中删除所有数字字符

select * from Actress  limit 5;
+-------+---------------------+
| code  | name                |
+-------+---------------------+
| 11455 | Hanshika_Motwani_19 |
| 11457 | Kajal_Agrwal_11     |
| 11458 | Ileana_21           |
| 11459 | Kaveri_Jha_11       |
| 11462 | Kaveri_Jha_18       |
+-------+---------------------+
5 rows in set (0.00 sec)

如何更新我的表以删除MysqL表中的数字字符,以便我可以得到如下结果

select * from Actress  limit 5;
+-------+---------------------+
| code  | name                |
+-------+---------------------+
| 11455 | Hanshika_Motwani_   |
| 11457 | Kajal_Agrwal_       |
| 11458 | Ileana_21           |
| 11459 | Kaveri_Jha_         |
| 11462 | Kaveri_Jha_         |
+-------+---------------------+
最佳答案
它看起来不是很好,但它的工作原理.它从字符串中删除任何数字

SELECT
    REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE (
    REPLACE( REPLACE( REPLACE( REPLACE('Hallo_1234567890_99','0',''),'1','2','3','4','5','6','7','8','9','');


update Actress 
SET name  = REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE (
        REPLACE( REPLACE( REPLACE( REPLACE(name,'');

如果您使用MariaDB,您可以使用REGEX_REPLACE:

update Actress
 set name =  REGEXP_REPLACE(name,'[0-9]','');

样品

MariaDB [(none)]> SELECT REGEXP_REPLACE('A1B2C44','');
+--------------------------------------+
| REGEXP_REPLACE('A1B2C44','') |
+--------------------------------------+
| ABC                                  |
+--------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>
原文链接:https://www.f2er.com/mysql/432854.html

猜你在找的MySQL相关文章