Home > Database > Mysql Tutorial > body text

How do we match values ​​with backslashes in a MySQL column, such as 'a\\b'?

王林
Release: 2023-08-29 19:21:08
forward
675 people have browsed it

我们如何匹配 MySQL 列中带有反斜杠的值,例如“a\\\\b”?

通过使用RLIKE运算符,我们可以进行这种类型的匹配。唯一的概念是在MySQL查询中使用一些反斜杠。下面的示例将更清楚地说明:

我们有以下表格,其中包含值为'a\b'和'a\b'。

mysql> select * from backslashes;
+------+-------+
| Id   | Value |
+------+-------+
|    1 | 200   |
|    2 | 300   |
|    4 | a\b  |
|    3 | a\b   |
+------+-------+
4 rows in set (0.10 sec)
Copy after login

现在假设我们想匹配值 ‘a\b’,那么我们需要写入八个反斜杠。这是因为第二个反斜杠没有被第一个反斜杠转义,所以为了比较两个字面量,我们需要将反斜杠加倍,但由于我们从MySQL字符串查询表中查询这样的字符串,所以这个加倍会发生两次 - 一次在客户端,一次在数据库中。因此,我们需要使用四个反斜杠,如下面的查询所示 −

mysql> Select * from backslashes where value RLIKE 'a\\\\b';
+------+-------+
| Id   | Value |
+------+-------+
|    4 | a\b  |
+------+-------+
1 row in set (0.00 sec)

mysql> Select * from backslashes where value RLIKE 'a\\b';
+------+-------+
| Id   | Value |
+------+-------+
|    3 | a\b   |
+------+-------+
1 row in set (0.01 sec)
Copy after login

The above is the detailed content of How do we match values ​​with backslashes in a MySQL column, such as 'a\\b'?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template