mysql的regex匹配多个字符串且不包含子串

 

mysql的regex匹配多个字符串且不包含子串,regex使用、mysql regex使用、mysql regex详解、regex的高级使用

 

camera_label字段是以逗号分割的字符串

 

1.查询包含 camera_2 标签的数据

select * from device_info_data where scope_type =2 and camera_label REGEXP ('camera_2');

 

查询结果:

 存在的问题:查询出包含camera_22的数据

 

2.查询包含 camera_2 和 camera_5 标签的数据

select * from device_info_data where scope_type =2 and camera_label REGEXP ('camera_2|camera_5');

  

查询结果:

  存在的问题:查询出包含camera_22的数据

 

3.查询包含 camera_2 标签的数据(不包含子串,比如不包含camera_22 

select * from device_info_data where scope_type =2 and camera_label REGEXP ('[[:<:]]camera_2[[:>:]]');

 

查询结果:

 存在的问题:不能查询多个字符串

 

4.查询包含 camera_2 和 camera_5 标签的数据(不包含子串,比如不包含camera_22和camera_51

select * from device_info_data where scope_type = 2 and camera_label REGEXP ('[[:<:]]camera_2[[:>:]]|[[:<:]]camera_5[[:>:]]');

  

查询结果:

 OK,大功告成,最优方案,既能查询出不包含camera_22的数据,也能查询多个字符串。

 

posted @ 2023-10-25 17:35  [浪子回头]  阅读(198)  评论(0编辑  收藏  举报