模糊查询(都是针对字符串操做的)
模糊查询有点相似于正则表达式,可是他没有正则表达式那么强大。正则表达式
通配符: _ 、 % 、 [] 、 ^ spa
_ 表示任意的单个字符串。
select * from Student_Info where Name like '张_'
这样就找出Student_Info 表中 Name列 张某的名字,两个字; 而不会查出张某某的名字。code
还有一种办法就是字符串
select * from Student_Info where Name like '张%' and len(Name)=2
怎么查个张某某,三个字的class
select * from Student_Info where Name like '张__'
%匹配任意多个 任意字符
查询 名字 中只要第一个字是 张。 无论有多少个字符。date
select * from Student_Info where Name like '张%'
[] 表示 筛选的范围。
查询姓张的 中间是个数字 第三个是汉字。select
select * from Student_Info where Name like '张[0-9]三'
查询姓张的 中间是个数字或者是字母, 第三个是汉字。查询
select * from Student_Info where Name like '张[0-9][a-z]三'
^ 表示非
查询张 某三, 就是中间不能是数字。di
select * from Student_Info where Name like '张[0-9]三'
拓展 替换 REPLACE 关键字
update Student_Info set Name=replace(Name,'张','李')
这样就把 姓张的 所有替换为姓李的。co