REPLACE new line character in MYSql not working

后端 未结 5 1231

I executed following query and for some reason its not replacing new line character in database . It says Rows matched 1 but no change . What can be wrong ?

mysq         


        
5条回答
  •  别那么骄傲
    2021-02-03 21:57

    this is what happening

    mysql> mysql> select * from t1 limit 3;
    +----------+------------+-----------+---------------------+
    | actor_id | first_name | last_name | last_update         |
    +----------+------------+-----------+---------------------+
    |        1 | PENELOPE   | GUINESS   | 2006-02-15 04:34:33 |
    |        2 | NICK       | WAHLBERG  | 2006-02-15 04:34:33 |
    |        3 | ED         | CHASE     | 2006-02-15 04:34:33 |
    +----------+------------+-----------+---------------------+
    3 rows in set (0.00 sec)
    
    mysql> update t1 set first_name=replace(first_name,'abc','') where first_name='ed';
    Query OK, 0 rows affected (0.00 sec)
    Rows matched: 10  Changed: 0  Warnings: 0
    
    mysql> select * from t1 limit 3;
    +----------+------------+-----------+---------------------+
    | actor_id | first_name | last_name | last_update         |
    +----------+------------+-----------+---------------------+
    |        1 | PENELOPE   | GUINESS   | 2006-02-15 04:34:33 |
    |        2 | NICK       | WAHLBERG  | 2006-02-15 04:34:33 |
    |        3 | ED         | CHASE     | 2006-02-15 04:34:33 |
    +----------+------------+-----------+---------------------+
    3 rows in set (0.00 sec)
    
    
    mysql> update t1 set first_name=replace(first_name,'ED','EDD') where first_name='ed';
    Query OK, 10 rows affected (0.00 sec)
    Rows matched: 10  Changed: 10  Warnings: 0
    
    mysql> select * from t1 limit 3;
    +----------+------------+-----------+---------------------+
    | actor_id | first_name | last_name | last_update         |
    +----------+------------+-----------+---------------------+
    |        1 | PENELOPE   | GUINESS   | 2006-02-15 04:34:33 |
    |        2 | NICK       | WAHLBERG  | 2006-02-15 04:34:33 |
    |        3 | EDD        | CHASE     | 2006-02-15 04:34:33 |
    +----------+------------+-----------+---------------------+
    
    3 rows in set (0.00 sec)
    

    What I meant is that the where condition it's working that's why you have 'rows matched: 1' but your replace don't find \\n to replace it, that's why changed: 0 so check your table data.

提交回复
热议问题