我有一个mysql表,其中有2个条目(id,title((int,text(
表中的一行伪数据看起来像
id title
1 apple"apple
我的查询打算在字段标题上进行搜索
select * from table1 where title='apple"apple';
我也试过使用
select * from table1 where title like('apple"apple');
上述查询似乎不起作用。
两个查询都返回空集。是否不可能搜索包含反斜杠的字符串?
PS::\作为转义双引号的一部分添加到数据库中。
确定吗?它按预期工作。
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)