gpt4 book ai didi

带有特殊字符的 Sql 查询 - 如何处理?

转载 作者:行者123 更新时间:2023-12-01 12:49:16 24 4
gpt4 key购买 nike

我有几个像

  1. john,1
  2. devil's
  3. corn


像这样的东西

现在,当我搜索这些名字时,我正在使用
select * from emp where empname like ('john,1,devil's,corn')

但是我没有得到预期值,我也收到了错误,因为 emp 名称包含特殊字符,如 , 和 '.

有人可以帮我解决这个问题吗?

最佳答案

这假设您的示例字符串中有 3 个离散名称

完全符合。你需要加倍引号。

select * from emp where
empname IN ('john,1' , 'devil''s', 'corn')

你也不能在 SQL Server 中 LIKE/IN。
select * from emp where
empname like '%john,1%'
OR
empname like '%devil''s%'
OR
empname like '%corn%'

关于带有特殊字符的 Sql 查询 - 如何处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4875015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com