create table student(
id char(36) primary key,
name varchar(8) not null,
age int(3) default 0,
mobile char(11),
address varchar(150)
)
insert into student
values ('9b4435ec-372c-456a-b287-e3c5aa23dff4','张三',24,'12345678901','北京海淀');
insert into student
values ('a273ea66-0a42-48d2-a17b-388a2feea244','李%四',10,'98765432130',null);
insert into student
values ('eb0a220a-60ae-47b6-9e6d-a901da9fe355','张李三',11,'18338945560','安徽六安');
insert into student
values ('6ab71673-9502-44ba-8db0-7f625f17a67d','王_五',28,'98765432130','北京朝阳区');
insert into student
values ('0055d61c-eb51-4696-b2da-506e81c3f566','王_五%%',11,'13856901237','吉林省长春市宽平区');
创建表:
利用like进行数据模糊查询
1.%:匹配0次或多次
例如:
select * from student where name like '张%'#查询姓张的学生信息
select * from student where name like '张三%'#查询张三
结果分别是:
2._:只匹配1次
例如:
select * from student where name like '张_'
select * from student where name like '张三_'
结果是:
第二种情况无法找到,因为“_”只能匹配一个字符,结果如下:
3.escape:取消%或_字符的通配符特性
例如:
select * from student where name like '%q%%' escape 'q'#查询姓名中含有%字符的学生信息
select * from student where name like '%q_%' escape 'q'#查询姓名中含有_字符的学生信息
select * from student where name like '%q%q%' escape 'q'#查询姓名结尾含有%%字符的学生信息
select * from student where name like '%李三'#查询姓名结尾含有李三的学生信息
结果分别为:
escape 后不可以是 '_' 或' %'