2016-08-06 8 views
-1

次の4つのステートメントを1つに組み合わせることは可能ですか?mysqlの更新と置換

UPDATE `comment_common` 
SET comment = replace(comment, '??', '?'); 

UPDATE `comment_common` 
SET comment = replace(comment, ' ?', '?'); 

UPDATE `comment_common` 
SET comment = replace(comment, '!!', '!'); 

UPDATE `comment_common` 
SET comment = replace(comment, ' !', '!'); 

答えて

0

あなたは、以下のような何かを試すことができます。

SET @str := '??'; 

SELECT 
REPLACE(
    REPLACE(
     REPLACE(
      REPLACE(@str,'??','?'),' ?','?'), 
      '!!','!' 
    ), 
' !', 
'!' 
) 

をお使いの場合:

UPDATE `comment_common` 
SET comment = REPLACE (
    REPLACE (
     REPLACE (
      REPLACE (
       comment, 
       '??', 
       '?' 
      ), 
      ' ?', 
      '?' 
     ), 
     '!!', 
     '!' 
    ), 
    ' !', 
    '!' 
)