【问题标题】:SQL select startwith (SQL Server) [duplicate]SQL选择startwith(SQL Server)[重复]
【发布时间】:2015-04-16 13:47:08
【问题描述】:

我需要查找以下划线开头的所有项目的列表:_

显而易见的行不通:

select * from role where Name like '_%'

这仍然返回所有项目。

以下也返回所有项目。

select * from role where Name like '\_%'
select * from role where Name like '__%'

有人知道如何转义下划线吗?或者我还能如何实现这个 StartWithUnderscore 功能?

【问题讨论】:

    标签: sql-server


    【解决方案1】:

    我找到了答案:

    select * from role where Name like '[_]%';

    【讨论】:

      【解决方案2】:

      您可以使用任何您想要的字符进行转义,例如

      select * from role where Name like '!_%' ESCAPE'!'
      

      您可以在此页面上阅读更多内容:LIKE (Transact-SQL)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-06
        • 2019-05-02
        • 1970-01-01
        • 1970-01-01
        • 2019-12-17
        • 1970-01-01
        • 2013-01-12
        • 2015-11-04
        相关资源
        最近更新 更多