【问题标题】:How to filter data with square brackets?如何用方括号过滤数据?
【发布时间】:2013-09-17 06:38:07
【问题描述】:

我在 MS Access 中有一个文本字段,它的文本如下:

bla bla bla [hhh] bla bla bla [kkkd]
blo blo blo blo [ttt] blo blo blo [ppp]
jh asdjahsuz uizasdui  asudz j jksdf 

我正在尝试搜索该字段中包含“[somthing]”的所有记录。

SELECT pruefhinweis
FROM tb_bauteile
WHERE pruefhinweis  LIKE '%[%]%'

但是这个 SQL 不起作用,你能告诉我我该怎么做这个工作吗?

【问题讨论】:

    标签: sql ms-access pattern-matching


    【解决方案1】:

    试试这个:

    SELECT pruefhinweis
    FROM tb_bauteile
    WHERE pruefhinweis LIKE '*[[a-z]]*';
    

    或者

    SELECT b.pruefhinweis
    FROM tb_bauteile AS b
    WHERE b.pruefhinweis Like '*[[]*]*';
    

    【讨论】:

    • @Kaja 请注意,无论[ 是否存在,模式都将匹配任何包含]pruefhinweis 值。这不是您的问题所要求的。
    【解决方案2】:

    在模式中匹配方括号并不直观。请参阅帮助主题“在字符串比较中使用通配符”

    您可以使用特殊字符开括号 ([ )、问号 (?)、数字符号 (#) 和星号 (*) 直接匹配自己,前提是它们被括在括号中。您不能在组内使用右括号 (]) 来匹配自身,但您可以在组外将其用作单个字符。

    通过从 DAO 运行的查询(例如,在使用查询设计器的 Access 会话中),这些中的任何一个都将返回您想要的结果。

    SELECT b.pruefhinweis
    FROM tb_bauteile AS b
    WHERE b.pruefhinweis Like '*[[]*]*';
    
    SELECT b.pruefhinweis
    FROM tb_bauteile AS b
    WHERE b.pruefhinweis ALike '%[[]%]%';
    

    在 ADO 中,您可以使用第二个查询或这个 ...

    SELECT b.pruefhinweis
    FROM tb_bauteile AS b
    WHERE b.pruefhinweis Like '%[[]%]%';
    

    【讨论】:

      【解决方案3】:
      SELECT pruefhinweis
      FROM tb_bauteile
      WHERE pruefhinweis  LIKE '*[*]*'
      

      【讨论】:

      • 感谢您的回答,但您的查询返回带有 * 的文本
      猜你喜欢
      • 1970-01-01
      • 2019-06-16
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 1970-01-01
      • 2015-09-14
      • 2021-10-09
      相关资源
      最近更新 更多