- SQL Server查询通配符小议
- SQL Server数据库30步检查安全列表
- 还原默认SQL Server Management S...
- 带你轻松接触 SQL Server 服务管理...
- 数据库优化之SQL语句性能调整原则
- DB2数据库SQL编码优化基础
- 最耗资源的SQL 写程序时千万注意
- 如何简化SQL Server数据库的复制
- SQL Server 下使用数据库链接
- 解析SQL Server的数据类型 BLOB
- 升级到SQL Server 2005的常见问题...
- SQL Server 数据导入:行为规范
- 解析SQL Server identity列的操作...
- SQL Server数据库和XML标识语言的...
- 轻松掌握SQL Server数据同步技术
Wildcard character | Description | Example |
% | Any string of zero or more characters. | WHERE title LIKE '%computer%' finds all book titles with the word 'computer' anywhere in the book title. |
_ (underscore) | Any single character. | WHERE au_fname LIKE '_ean' finds all four-letter first names that end with ean (Dean, Sean, and so on). |
[ ] | Any single character within the specified range ([a-f]) or set ([abcdef]). | WHERE au_lname LIKE '[C-P]arsen' finds author last names ending with arsen and starting with any single character between C and P, for example Carsen, Larsen, Karsen, and so on. |
[^] | Any single character not within the specified range ([^a-f]) or set ([^abcdef]). | WHERE au_lname LIKE 'de[^l]%' all author last names starting with de and where the following letter is not l. |
有时候,应用程序需要提供对通配符本身的搜索(literally search),各家DB vendor就采用了不同的策略和实现,下面是SQLSERVER的做法:
Literal | Verification | Symbol |
% | If(@inputTerm contains (‘%’,’_’)) | LIKE ‘[%]’ |
_ | If(@inputTerm contains (‘%’,’_’)) | LIKE ‘[_]’ |
[ ] | If(@inputTerm contains ('[]')) | LIKE ‘![!]’ ESCAPE ‘!’ |
[^] | If(@inputTerm contains ('[^]')) | LIKE ‘![!^!]’ ESCAPE ‘!’ |
看到了吧,第一,二种都能看懂。看到后两个,LIKE后面出现了ESCAPE关键字,这是什么意思?
简单的说,就是SQLSERVER允许你自己“创造”通配符,我这里用了!作为我的自定义符号,用ESCAPE标识,编译过之后,引擎做LIKE句式时就会把!作为新的“单字符替代”通配符。
