当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - How can I change a MySQL Text field so that all values are prefaced by "-"

问题描述:

I have a table "foo" with a varchar field "text" where some rows are prefixed with a "-" and others are not. What's the best way to update rows so that the "text" field begins with a "-" sign?

网友答案:
UPDATE foo SET text = concat('-', text) WHERE substring(text, 1, 1) <> '-'
网友答案:

This should do the trick:

UPDATE Foo
SET textField = CASE WHEN LEFT(textField,1) = '-' THEN textField 
                     ELSE CONCAT('-', textField) END
网友答案:
UPDATE `foo`
  SET `text` = CONCAT('-', text)
  WHERE SUBSTR(text, 1, 1) <> '-';
网友答案:
UPDATE foo
SET `text` = CONCAT('-', `text`)
WHERE `text` NOT LIKE '-%'
分享给朋友:
您可能感兴趣的文章:
随机阅读: