【发布时间】:2015-01-21 00:02:25
【问题描述】:
我创建了这张表:
create table if not exists `example`(
`firstNames` varchar(45) not null,
`secondNames` varchar(45) not null)
ENGINE = InnoDB;
现在我插入一行:
insert into example values('Jose Alonzo', 'Pena Palma');
然后检查是否正确
select * from example;
| firstNames | secondNames |
----------------------------
| Jose Alonzo| Pena Palma |
没关系! 简单 现在我创建一个语句来搜索这一行
set @search = 'jose alonzo pena';
select * from example
where concat(firstNames, ' ', secondNames) like concat('%',@search,'%');
这个回报
| firstNames | secondNames |
----------------------------
| Jose Alonzo| Pena Palma |
现在我将值 @search 更改为“jose pena”
set @search = 'jose pena';
select * from example
where concat(firstNames, ' ', secondNames) like concat('%',@search,'%');
并且什么都不返回!
| firstNames | secondNames |
发生了什么? 我不能对 varchar 中间的字符使用 like 吗?
【问题讨论】: