问题描述:
使用SQLServer执行 select * from users where username like ‘%123[曹操]’;
语句进行模糊匹配时没有数据。
问题解决:
SQL语句中含有特殊符号,特殊字符一般都是通配符,需要进行转义处理。
特殊字符:[(中括号),%(百分号),_ (下划线)^尖号),!(感叹号)。
解决方法:
1、用方括号[]转义字符
处理格式:[特殊字符]。
实例:select * from users where username like ‘%123[[]曹操]’;
2、使用escape 转义字符
说明:在语句中,当转义符置于特殊字符之前时,该通配符就解释为普通字符。
处理格式:’转义符 特殊字符’ escape ‘转义符’。
实例:
select * from users where username like ‘%123[曹操]’ escape ”;
select * from users where username like ‘%123/[曹操]’ escape ‘/’;
select * from users where username like ‘%123|[曹操]’ escape ‘|’;
select * from users where username like ‘%123^[曹操]’ escape ‘^’;//不建议
select * from users where username like ‘%123![曹操]’ escape ‘!’;//不建议
————————————————
版权声明:本文为CSDN博主「旭东怪」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_38974638/article/details/107564092

您需要登录 或注册 后才可以发表评论。