带条件的查询—模糊查询

此文转载自:https://blog.csdn.net/weixin_43472073/article/details/110258712#commentBox

模糊查询(都是针对字符串操作的)

模糊查询有点类似于正则表达式,但是他没有正则表达式那么强大。

通配符:  _   、 % 、   []  、   ^   

    _  表示任意的单个字符串。

select * from Student_Info where Name like '张_'

这样就找出Student_Info 表中 Name列 张某的名字,两个字;  而不会查出张某某的名字。

还有一种办法就是

select * from Student_Info where Name like '张%' and len(Name)=2

怎么查个张某某,三个字的

select * from Student_Info where Name like '张__'

%匹配任意多个 任意字符

查询 名字 中只要第一个字是 张。  不管有多少个字符。

select * from Student_Info where Name like '张%'

 

[] 表示 筛选的范围。

查询姓张的 中间是个数字 第三个是汉字。

select * from Student_Info where Name like '张[0-9]三'

查询姓张的 中间是个数字或者是字母,  第三个是汉字。

select * from Student_Info where Name like '张[0-9][a-z]三'

^  表示非

查询张 某三,  就是中间不能是数字。

select * from Student_Info where Name like '张[0-9]三'

拓展  替换 REPLACE  关键字

update Student_Info set Name=replace(Name,'张','李')

这样就把 姓张的 全部替换为姓李的。

   

更多内容详见微信公众号:Python测试和开发

Python测试和开发

原文地址:https://www.cnblogs.com/phyger/p/14061030.html