我将下面的值插入到用户表中,
~\`!@%23$%^%26*()-=_+{}[]|\\:;\"'<>?,./然后用like查询它,got什么也没有,但是=工作正确,为什么LIKE子句不能工作呢?
准备数据
CREATE TABLE `users` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);
insert into users(name) values('~`!@%23$%^%26*()-=_+{}[]|\\\\:;\\"\'<>?,./');
insert into users(name) values('test'); 查询
select * from users where name like '%~`!@%23$%^%26*()-=\_+{}[]|\\\\:;\\"\'<>?,./%'; // Got nothing
select * from users where name='~`!@%23$%^%26*()-=_+{}[]|\\\\:;\\"\'<>?,./'; // Got the inserted data即使我逃过了%和_,它还是不起作用。
select * from users where name like '%~`!@\%23$\%^\%26*()-=\_+{}[]|\\\\:;\\"\'<>?,./%'; // Still got nothing预期
执行时
select * from users where name like '%~`!@%23$%^%26*()-=\_+{}[]|\\\\:;\\"\'<>?,./%'; // Got nothing它应该只得到这张唱片
~\`!@%23$%^%26*()-=_+{}[]|\\:;\"'<>?,./发布于 2022-05-17 08:40:16
您可以像这样使用concat (不确定MySQL或其他DB类型,但原则是相同的):
select * from users
where name like
'%' || '~`!@%23$%^%26*()-=\_+{}[]|\\\\:;\\"\'<>?,./' || '%';这是[医]小提琴
由于新行的新问题,我用ESCAPE.修复了我的代码。
select *
from users
where name like
'%~`!@%23$#%^#%26*()-=\_+{}[]|\\\\:;\\"\'<>?,./%' --<< escape # before % character
escape '#';发布于 2022-05-17 09:13:37
您可以使用INSTR:
SELECT * FROM users
WHERE INSTR(name, '~`!@%23$%^%26*()-=\_+{}[]|\\\\:;\\"\'<>?,./') > 0 https://stackoverflow.com/questions/72270534
复制相似问题