【问题标题】:Check string with special character in SQL在 SQL 中检查带有特殊字符的字符串
【发布时间】:2014-10-30 19:38:13
【问题描述】:

我正在查询从像

这样的表中获取值
Select email from cust Where name = " John carter's "

由于字符串中的单引号导致我收到错误......

请帮我解决上述问题

【问题讨论】:

标签: mysql sql ms-access


【解决方案1】:

这应该可行:

Select email from cust Where name = " John carter''s" 

【讨论】:

  • 如果我有这种类型的查询,然后选择来自 cust 的电子邮件 Where name = 'John Carter's'
  • @user3656418 在这种情况下,在第二个单引号之前只添加另一个 ',如下所示:Select email from cust Where name = " John carter''s''"
【解决方案2】:

如果这是你现在需要得到的东西......

Select email from cust Where name LIKE "%John carter%"

或者你可以省略撇号:

Select email from cust Where name = " John carter''s" 

【讨论】:

  • 如果我有这种类型的查询,请选择来自 cust 的电子邮件,其中 name = 'John Carter's'
【解决方案3】:

为什么不用转义字符?

这样

Select email from cust Where name = " John carter''s "

【讨论】:

  • 如果我有这种类型的查询,请选择来自 cust 的电子邮件,其中 name = 'John Carter's'
【解决方案4】:

您遇到的问题是由于(取决于您使用的数据库程序)单引号 ' 是 SQL 数据建模语言 (DML) 分隔符,因此 SQL 解析器可能不会能够妥善处理。

【讨论】:

    猜你喜欢
    • 2012-03-23
    • 2011-05-29
    • 1970-01-01
    • 2019-09-10
    • 2016-01-14
    • 2013-11-27
    • 2020-03-18
    相关资源
    最近更新 更多