[英]MySQL - Add word to the end of a text column
I need to add word 'example' to the end of a text column keywords
. 我需要在文本列
keywords
的末尾添加单词“example”。
If the column already contains some text, added word will be separated by a space : 如果列已包含某些文本,则添加的单词将用空格分隔 :
Column `keywords` = '';
Add word 'example'
Result `keywords` = 'example'
BUT 但
Column `keywords` = 'Some text'
Add word 'example'
Result `keywords` = 'Some text example'
UPDATE table
SET keyword=(
CASE WHEN keyword=''
THEN 'example'
ELSE concat(keyword,' example')
END
);
select concat(keyword,' example') from tbl ;
EDITED: To update,use below: 编辑:要更新,请使用以下内容:
UPDATE table
SET keyword = CASE keyword WHEN '' THEN 'example' ELSE concat(keyword,' example') END;
Here is another approach that some may prefer: 这是另一种方法,有些人可能更喜欢:
UPDATE `table` SET `keywords` = TRIM(CONCAT(`keywords`, ' ', 'example'))
This will not leave a leading space if the field is empty. 如果该字段为空, 则不会留下前导空格。
Try this: 试试这个:
Select CONCAT(keywords,'example') from myTable 从myTable中选择CONCAT(关键字,'示例')
try this: 试试这个:
UPDATE table
SET `keyword` = CONCAT(`keyword`, ' ', 'example')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.