在MYSQL查询中将REGEXP转换为LIKE

时间:2022-05-01 12:17:46

I have MYSQL query that looks as below

我有MYSQL查询,如下所示

select * from table1 where host REGEXP 'host1';

I want to execute the same query using LIKE Please suggest how it can be achieved

我想用LIKE执行相同的查询请建议如何实现

2 个解决方案

#1


3  

Try this:

尝试这个:

select * from table1 where host LIKE '%host1%';

REGEXP 'host1' will match host1 anywhere in the string. To phrase this using the LIKE operator we need to surround host1 with wildcards.

REGEXP'host1'将匹配字符串中任何位置的host1。要使用LIKE运算符对此进行短语,我们需要使用通配符包围host1。

#2


0  

You can try using %

你可以尝试使用%

select * from table1 where host LIKE '%host1%';

#1


3  

Try this:

尝试这个:

select * from table1 where host LIKE '%host1%';

REGEXP 'host1' will match host1 anywhere in the string. To phrase this using the LIKE operator we need to surround host1 with wildcards.

REGEXP'host1'将匹配字符串中任何位置的host1。要使用LIKE运算符对此进行短语,我们需要使用通配符包围host1。

#2


0  

You can try using %

你可以尝试使用%

select * from table1 where host LIKE '%host1%';