简体   繁体   中英

How to remove a specific part of string on a specific field on table?

Today I discovered that on my production database the field name of some record also contains &nbsp , so there are thousands of record that contains in name field this type of structure: Mamurrasi vs. Internacional Tirana 

So I am wondering if I can remove   from this record without damage the database.

For find it I used: SELECT * FROM venue WHERE name LIKE "%&nbsp%"`

You can use replace:

update venue
    set name = trim(replace(name, '&nbsp', ' '))
    where name like '%&nbsp%';

This replace &nbsp with a space and then removes unnecessary spaces from the beginning and end of the string.

&nbsp is the html code for a non-breaking space. It makes more sense to replace it with a space than to to remove it entirely.

Assuming that this is Oracle and you want to replace ' ' by ' ' :

UPDATE venue v SET v.name = REPLACE(v.name, ' ', ' ');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM