使用通配符进行过滤
2019-08-05 本文已影响0人
骑着白龙马的猪八戒
通配符 用来匹配值的一部分的特殊字符
% 表示任何字符(包括没有字符)出现的任意次数
select prod_id,prod_price,prod_name from products where prod_name like 'jet%';
可以设置Mysql区分大小写,如果区分大小写的话,jet%与JetPack 1000不匹配
![](https://img.haomeiwen.com/i13805608/41123524a8bbc922.png)
select prod_id,prod_price,prod_name from products where prod_name like '%anvil%';
可以使用多个通配符
![](https://img.haomeiwen.com/i13805608/63dcdf8a6e6e863f.png)
'_'通配符 用途和%差不多,但是只匹配单个字符
select prod_id,prod_price,prod_name from products where prod_name like '_ ton anvil';
![](https://img.haomeiwen.com/i13805608/1c52054a78daa4b0.png)
select prod_id,prod_price,prod_name from products where prod_name like '% ton anvil';
%与_的区别:
![](https://img.haomeiwen.com/i13805608/bcc71b17f20060a4.png)