不知道大家对SQL系列的感不感兴趣 先在这里探个路 本文针对的读者为SQL菜鸟 欢迎大牛驳论或者补充
既然是探路篇 就先说下数据过滤中的偏门匹配 希望能给大家带来收获
create table 虫子的临时表( 编号 varchar(30), 名称 varchar(30), 备注 varchar(100))insert into 虫子的临时表 values('编号01','name01','这是一个奇迹')insert into 虫子的临时表 values('编号02','name02','这是一个神话')insert into 虫子的临时表 values('编号039','name039','这是一个扯谈')-- %大家都懂的select * from 虫子的临时表 where 编号 like '%编号%'-- 使用‘_’匹配任意字符select * from 虫子的临时表 where 编号 like '编号0_'-- 使用‘_’匹配任意字符 但是只能匹配任意单个字符select * from 虫子的临时表 where 编号 like '编号_'-- 使用‘_’匹配任意字符 但是只能匹配任意单个字符 如果要表示2个字符可以用‘__’select * from 虫子的临时表 where 编号 like '编号__'drop table 虫子的临时表
“_”通配符功能和“%”相似,只是“_”表示任意单个字符,且该字符只能匹配一个字符。
create table 虫子的临时表( 昵称 varchar(30), 座位号 int, 备注 varchar(100))insert into 虫子的临时表 values('和谐',15,'这是一个奇迹')insert into 虫子的临时表 values('特色社会主义',29,'这是一个神话')insert into 虫子的临时表 values('%#¥',31,'这是一个扯谈')insert into 虫子的临时表 values('Qg%Q',31,'这是一个扯谈')-- '[]'匹配某一范围内的字符select * from 虫子的临时表 where 座位号 like '[1-2][1-9]'-- '[^]'匹配非某一范围内的字符select * from 虫子的临时表 where 座位号 like '[^1-2]_'-- 匹配特殊字符select * from 虫子的临时表 where 昵称 like '%[%#]%'-- 在模式查询中使用转义符escapeselect * from 虫子的临时表 where 昵称 like '%g%%' escape '/'drop table 虫子的临时表
“[]”通配符用于指定一系列的字符,只要满足这些字符其中之一,且位置出现在“[]”通配符的位置的字符串就满足查询条件。“[^]”来排除指定数据。like关键字可以与“[]”通配符组合来匹配特殊字符也可以使用escape关键字和转义符来实现。
下一章节和大家详细介绍下游标。