doujiu3768 2016-09-28 08:20
浏览 63
已采纳

在MySQL中选择一些特殊字符时的奇怪行为

I have a row, which have column url with the following value:

http://example.com/a~~1234567890-=!@#$%^&*()_+[\"test\"]

When I execute the following query:

SELECT * FROM `mytable` WHERE `url` = 'http://example.com/a~~1234567890-=!@#$%^&*()_+[\"test\"]'

MySQL says that record is not exists.

  • 写回答

1条回答 默认 最新

  • douchen4915 2016-09-28 08:35
    关注

    You need to escape the \ in your two \" since \" is an escape sequence: only the quote " will remain in the executed query.

    \" [is an escape sequence turned into a] double quote (“"”) character
    \\ [is an escape sequence turned into a] backslash (“\”) character

    http://dev.mysql.com/doc/refman/5.7/en/string-literals.html

    So

    SELECT * FROM `mytable` WHERE `url` = 'http://example.com/a~~1234567890-=!@#$%^&*()_+[\\"test\\"]'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi