SQL Command for removing characters like '!' or '*' from data in a MySQL column
I suspect thi开发者_运维问答s to be a relatively easy fix for someone with a greater grasp on SQL.
Some of the data in the 'Name' field of my db have a '!' or '*' in the name, usually at the beginning of the name. I want to remove those unnecessary characters.
Is there an SQL command that will achieve such a lofty goal with alacrity and simplicity?
Thanks in advance.
Use MySQL REPLACE
function in a UPDATE
query without any WHERE
clause like this:
UPDATE tablename SET Name = REPLACE(Name, '!', '');
UPDATE tablename SET Name = REPLACE(Name, '*', '');
To do it in a single query, you can use this:
UPDATE tablename SET Name = REPLACE(REPLACE(Name, '*', ''), '!', '');
SELECT REPLACE(REPLACE(column,'!',''),'*','')
perhaps? See http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace
精彩评论