SQL UPDATE在字段/列中添加值。

时间:2022-01-11 07:52:54

Here is what I want to do:

下面是我想做的:

current table:

当前表:

+----+-------------+
| id | data |
+----+-------------+
| 1 | cow cow2 |
| 2 | cat cat2 |
| 3 | cam cam2 |
| 4 | cal cal |
+----+-------------+

+ - - - - - - - - - - - - - - - - - - | + | | id数据+ - - - + - - - - - - - - - - - - - + | 1 |牛cow2 | | 2 |猫cat2 | | 3 |凸轮cam2 | | 4 |卡尔卡尔| + - - - + - - - - - - - - - - - - - +

here is what I want

这就是我想要的。

+----+-------------+
| id | data |
+----+-------------+
| 1 | cow a cow2 |
| 2 | cat a cat2 |
| 3 | cam a cam2 |
| 4 | cal a cal |
+----+-------------+

+ - - - - - - - - - - - - - - - - - - | + | | id数据+ - - - + - - - - - - - - - - - - - + | 1 |牛cow2 | | 2 |猫cat2 | | 3 |凸轮cam2 | | 4 |卡尔卡尔| + - - - + - - - - - - - - - - - - - +

thats it! I just want to add one little word between 2 already existing in my databases tables and wonder how this can be done?

这就是它!我只是想在我的数据库表中添加两个已经存在的单词,并且想知道如何做到这一点?

2 个解决方案

#1


2  

you can simply replace the space character with a space, the letter a and another space

你可以简单地用空格代替空格,字母a和另一个空格。

UPDATE foo
SET data = REPLACE(data, ' ', ' a ');

#2


0  

Use the Replace function

使用替换函数

    UPDATE tableName
   SET data = REPLACE(data, ' ', 'a')

#1


2  

you can simply replace the space character with a space, the letter a and another space

你可以简单地用空格代替空格,字母a和另一个空格。

UPDATE foo
SET data = REPLACE(data, ' ', ' a ');

#2


0  

Use the Replace function

使用替换函数

    UPDATE tableName
   SET data = REPLACE(data, ' ', 'a')