escape在sqlserver中的使用--【叶子】
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 原创作品,转贴请注明作者和出处,留此信息。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |