sql delete a value in a field separated by commas

Delete a certain value in a comma-separated field in the table, Insert image description here
delete 232 in it
to make the result become 11,4243,2423,14134,453
and use replace to replace it with empty, there will be a problem with the remaining comma

practice:

update data_test set name = trim(both ',' from replace(concat(',', name, ','), ',232,', ','));

explain:

First splicing two commas at the beginning and end of the name field becomes:,11,232,4243,2423,14134,453, and then uses replace to
replace,232, with a comma, and the string becomes:,11,4243,2423, 14134,453, and then use trim(both from)
to remove the commas at the beginning and end to delete the specified characters and commas. The same logic applies to removing characters at the beginning and end or any section in the middle.

Reference article:
trim implements the removal of specified characters and commas in a string

Guess you like

Origin blog.csdn.net/s990420/article/details/129021555