使用CONCATENE字段进行SQL更新
为什么大家, 我有下表使用CONCATENE字段进行SQL更新,sql,concatenation,Sql,Concatenation,为什么大家, 我有下表 mysql> select * from recipes; +------+-------+ | id | direct| +------+-------+ | 1 | max | | 2 | linda | | 3 | sam | | 4 | henry | +------+-------+ 但是需要更新所有直接字段,并将{{}放在字段的开头和结尾 +------+-----------+ | id | direct
mysql> select * from recipes;
+------+-------+
| id | direct|
+------+-------+
| 1 | max |
| 2 | linda |
| 3 | sam |
| 4 | henry |
+------+-------+
但是需要更新所有直接字段,并将{{}
放在字段的开头和结尾
+------+-----------+
| id | direct |
+------+-----------+
| 1 | {{max}} |
| 2 | {{linda}} |
| 3 | {{sam}} |
| 4 | {{henry}} |
+------+-----------+
我该怎么做
我尝试了updaterecipes SET direct='{“step”:[{“description”:“'+direct+”,“image”:“}]}'
,但它对我不起作用
请帮帮我 以下是一种适用于任何数据库的方法:
UPDATE recipes
SET direct = REPLACE('{{x}}', 'x', direct);
试试这个。。使用concat
update recipes set direct = concat('{{',direct,'}}')
我试过了,但是所有的直接数据都被转换成“0”gordon的解决方案应该可以正常工作。。。还有Concatt这似乎是个很糟糕的主意。最多,您应该为此使用计算列。