escape在sqlserver中的使用--【叶子】
1、escape是干什么用的?
escape相对于转移字符
2、escape在什么情况下使用?
举例说明:
例如我们要进行模糊查询:
--测试数据
declare @tablea table (id int ,col varchar(20))
insert into @tablea
select 1,'maco' union all
2,'mao' union all
3,'micro'
--模糊查询
* from @tablea where col like '%ma%'
/*结果
id col
----------- --------------------
1 maco
2 mao
*/
这是最普通的模糊查询了
但是当col列含有特殊字符例如%%的时候
@tableb table (id int ,"serif"; mso-no-proof: yes;'> into @tableb
union all
union all
* from @tableb where col like '%%a%%'
上面这句就不行了,结果相当于%a%,有a的都出来了
/*
结果:
1 m%a%co
2 m%a%o
3 miacro
此时我们可以用escape来处理
@tablec table (id int ,"serif"; mso-no-proof: yes;'> into @tablec
* from @tablec where col like '%$%a$%%' escape '$'
2 m%a%o
*/
@【叶子】http://blog.csdn.net/maco_wang 原创作品,转贴请注明作者和出处,留此信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。