MySQL Replace quotes with brackets
Hey everyone, I've got a problem and Google hasn't开发者_如何学Python yielded the help I need so I'm turning to the experts ;)
I've got a MySQL database and one field is used for user input. Some users feel the need to quote their entry like so: "cheese press" and I need to change all entries in that column that have "quotes" to brackets like so: (cheese press)
I've tried these:
UPDATE `inputColumn` SET `userInput` = REPLACE(`userInput`, '"', '(');
The results were obvious the second I hit enter: (cheese press( I did this on a test field, no worries.
Then I tried:
UPDATE `inputColumn` SET `userInput` = REPLACE(`userInput`, '"%', '(');
That didn't do anything at all and neither did
UPDATE `inputColumn` SET `userInput` = REPLACE(`userInput`, '"%"', '(%)');
I really don't want to go through and update 3000 records manually :) any ideas?
Perhaps something like this.
UPDATE `inputColumn`
SET `userInput` = CONCAT('(', SUBSTR(`userInput`, 2, LENGTH(`userInput`)-2), ')')
WHERE `userInput` LIKE '"%"';
Its a bit of a cludge but if you can trust that there is a space before the first quote and a space after the second then try
UPDATE `inputColumn` SET `userInput` = REPLACE(`userInput`, ' "', ' (');
and
UPDATE `inputColumn` SET `userInput` = REPLACE(`userInput`, '" ', ')');
Note the spaces and different brackets.
精彩评论