• ADADADADAD

    【记录】mysql使用like匹配数据时关于通配符的使用误区[ mysql数据库 ]

    mysql数据库 时间:2024-12-25 09:58:31

    作者:文/会员上传

    简介:

    -- 此sql中“_”为通配符,匹配任意单字符,所以过滤的数据包含了test开头的数据:select * from live_class where title like 'test_%';解决方案:-- 下面两种实现的效果一样(个人

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    -- 此sql中“_”为通配符,匹配任意单字符,所以过滤的数据包含了test开头的数据:

    select * from live_class where title like 'test_%';

    解决方案:
    -- 下面两种实现的效果一样(个人偏向于第2种,比较符合后台开发的用法习惯):

    select * from live_class where title like 'test/_%' escape '/';select * from live_class where title like 'test\_%';

    注:“_”和“%”的区别在于,通配符“_”为匹配任意单字符,而“%”为任意个字符