替换 mySQL 中包含引号的单词时出错

发布于 2024-08-04 07:11:59 字数 218 浏览 4 评论 0原文

我已经更新了许多记录,但是当涉及到包含引用的单词时,我收到此错误:“错误:未关闭的引用@ 1357”

我知道为什么它给我这个错误,我只是不知道如何解决它。

这是一个示例: UPDATE invnum SET cAccountName = Replace(cAccountName,'JOHN'S','BEN')

提前致谢。

I have updated many records already, but when it came to a word that contains a quote I get this error: "ERROR: Unclosed quote @ 1357"

I know why it's giving me this error, I just don't how to solve it.

Here's a sample:
UPDATE invnum SET cAccountName = replace(cAccountName,'JOHN'S','BEN')

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅紫色的梦幻 2024-08-11 07:11:59

在字符串中转义引号:

UPDATE invnum SET cAccountName = replace(cAccountName,'JOHN\'S','BEN')

你要非常小心这一点 - 没有正确处理这一点是 SQL注入攻击,是安全问题的一个主要来源。

Escape quotes inside strings:

UPDATE invnum SET cAccountName = replace(cAccountName,'JOHN\'S','BEN')

You want to be really careful with this - not dealing with this properly is the source of SQL injection attacks, and is a major source of security problems.

听风吹 2024-08-11 07:11:59

如果您使用脚本来更新记录,请使用内置转义函数。对于 php,这将是 mysql_real_escape_string

if you’re using a script to update your records use a builtin escaping function. for php that would be mysql_real_escape_string

后eg是否自 2024-08-11 07:11:59

尝试这样做:

UPDATE invnum SET cAccountName = replace(cAccountName,"JOHN'S","BEN")

如果您需要在字符串中使用两种类型的引号,那么当它们出现在字符串中时,您需要对用于包围字符串的引号类型进行转义(否则 SQL 解释器会认为字符串在之前结束)它确实如此。

例如:

Johns   becomes "Johns"
John's  becomes "John's" or 'John\'s'
"John"  becomes '"John"' or "\"John\""

等等。

Try this instead:

UPDATE invnum SET cAccountName = replace(cAccountName,"JOHN'S","BEN")

If you need to use both types of quotes within a string, then you'll need to escape the type of quotes you use to surround the string when they occur within it (otherwise the SQL interpreter will think the string ends before it actually does.

For instance:

Johns   becomes "Johns"
John's  becomes "John's" or 'John\'s'
"John"  becomes '"John"' or "\"John\""

et cetera.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文