在MySQL中搜索包含反斜杠的文本

h22fl7wq  于 2022-10-03  发布在  Mysql
关注(0)|答案(1)|浏览(207)

我有一个MySQL表,其中有2个条目(id,标题)(int,文本)

表中的一行虚拟数据如下所示

id title
1  apple"apple

我的查询打算在字段标题上进行搜索

select * from table1 where title='apple"apple';

我也试着用

select * from table1 where title like('apple"apple');

上述查询似乎没有起到很好的作用。

这两个查询都返回空集。难道不能搜索其中包含反斜杠的字符串吗?

PS::\作为转义双引号的一部分添加到数据库中。

hfyxw5xn

hfyxw5xn1#

好的?它的工作方式与预期一致。

mysql> CREATE TABLE MyTbl (id INT, title TEXT);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO MyTbl VALUES(1,'apple "apple');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM MyTbl;
+------+-------------+
| id   | title       |
+------+-------------+
|    1 | apple"apple |
+------+-------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM MyTbl WHERE title = 'apple "apple';
+------+-------------+
| id   | title       |
+------+-------------+
|    1 | apple"apple |
+------+-------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM MyTbl WHERE title like('apple "apple');
+------+-------------+
| id   | title       |
+------+-------------+
|    1 | apple"apple |
+------+-------------+
1 row in set (0.00 sec)

可能是和太空角色有关吧?

mysql> SELECT * FROM MyTbl WHERE title = 'apple"apple';
Empty set (0.00 sec)

mysql> SELECT * FROM MyTbl WHERE title = 'apple "apple';
+------+--------------+
| id   | title        |
+------+--------------+
|    1 | apple "apple |
+------+--------------+
1 row in set (0.00 sec)

运行这个命令怎么样?它给你的回报是什么?

mysql> SELECT @NO_BACKSLASH_ESCAPES;
+----------------------------------------------+
| @NO_BACKSLASH_ESCAPES                        |
+----------------------------------------------+
| NULL                                         |
+----------------------------------------------+
1 row in set (0.00 sec)

相关问题