如何在MySql中转义撇号(')?

How to escape apostrophe (#39;) in MySql?(如何在MySql中转义撇号()?)
本文介绍了如何在MySql中转义撇号(')?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

MySQL 文档说它应该是 \'.但是,scite 和 mysql 都显示 '' 有效.我看到了,它的工作原理.我该怎么办?

解决方案

您引用的 MySQL 文档实际上比您提到的要多一些.它还说,

<块引用>

在用'"引用的字符串中的'"可以写成''".

(另外,您链接到 MySQL 5.0 版本的表 8.1.特殊字符转义序列,当前版本是 5.6 — 但当前的 表 8.1.特殊字符转义序列看起来非常相似.)

我认为 Postgres 注释backslash_quote (string) 参数 提供信息:

<块引用>

这控制引号是否可以在字符串文字中用 \' 表示.表示引号的首选 SQL 标准方式是将引号加倍 (''),但 PostgreSQL 历来也接受 \'.但是,使用 \' 会带来安全风险...

这对我说,与使用反斜杠转义单引号相比,使用双引号字符是更好的整体和长期选择.

现在,如果您还想在等式中添加语言选择、SQL 数据库及其非标准特性的选择以及查询框架的选择,那么您最终可能会有不同的选择.你没有提供太多关于你的约束的信息.

The MySQL documentation says that it should be \'. However, both scite and mysql shows that '' works. I saw that and it works. What should I do?

解决方案

The MySQL documentation you cite actually says a little bit more than you mention. It also says,

A "'" inside a string quoted with "'" may be written as "''".

(Also, you linked to the MySQL 5.0 version of Table 8.1. Special Character Escape Sequences, and the current version is 5.6 — but the current Table 8.1. Special Character Escape Sequences looks pretty similar.)

I think the Postgres note on the backslash_quote (string) parameter is informative:

This controls whether a quote mark can be represented by \' in a string literal. The preferred, SQL-standard way to represent a quote mark is by doubling it ('') but PostgreSQL has historically also accepted \'. However, use of \' creates security risks...

That says to me that using a doubled single-quote character is a better overall and long-term choice than using a backslash to escape the single-quote.

Now if you also want to add choice of language, choice of SQL database and its non-standard quirks, and choice of query framework to the equation, then you might end up with a different choice. You don't give much information about your constraints.

这篇关于如何在MySql中转义撇号(')?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)