-->Title:生成測試數據
-->Author:wufeng4552
-->Date :2009-09-22 09:27:36
declare @t table([test] nvarchar(5))
Insert @t
select N'11%22' union all
select N'11%33' union all
select N'12%33' union all
select N'1_%33'
--1
--使用ESCAPE关键字定义转义符。在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符。
--如搜索包含'1%'的紀錄
select * from @t where [test] like '%1/%%' escape '/'
/*
test
-----
11%22
11%33
(2 個資料列受到影響)
*/
--2
--允许在字符串中搜索通配符而不是将其作为通配符使用
select * from @t where [test] like '%1/_%' escape '/'
/*
test
-----
1_%33
*/
MSSQL escape的主要用途
最新推荐文章于 2025-05-13 10:44:26 发布
本文介绍了如何在SQL查询中使用ESCAPE关键字定义转义符,以便能够精确地搜索包含通配符的字符串数据。通过具体示例展示了如何将通配符作为普通字符进行匹配。
631

被折叠的 条评论
为什么被折叠?



