gpt4 book ai didi

mysql - 在 SQL 中更新字符串的一部分

转载 作者:行者123 更新时间:2023-11-29 02:21:37 25 4
gpt4 key购买 nike

我想更新数据库特定列中的一部分字符串。

我的数据库的特定列中有 cm2,我想将其更新为 cm2。

我查找 cm2 的 sql 查询是:

SELECT * 
FROM `question_table`
WHERE `option` LIKE '%cm2%'

要更新我想尝试的是:

Update question_table.option
set Value = replace(value,'cm2','cm<sup>2</sup>').

不确定这是否正确。在这方面需要一些指导。

编辑:

语法:

UPDATE question_table SET option = Replace(option, 'cm2','cm<sup>2</sup>')
WHERE option LIKE '%cm2%'

它抛出一个错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option = Replace(option, 'cm2','cm<sup>2</sup>') WHERE option LIKE '%cm2%'' at line 1

最佳答案

出现错误的原因可能是 option 是 MySql 中的保留字。要转义 MySql 中的保留字,请使用此字符 `:

UPDATE question_table 
SET `option` = Replace(`option`, 'cm2','cm<sup>2</sup>')
WHERE `option` LIKE '%cm2%'

Here is a list of reserved words in MySql

Here is my favorite method of avoiding the use of reserved words.

关于mysql - 在 SQL 中更新字符串的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com