表名:info_user
字段:id、name、borndata、age、sex、email、sail
4. like 操作符
4.1 % 通配符
<span style="white-space:pre"> </span>SELECT id,name,borndata FROM info_user WHERE name LIKE 'j%';
<span style="white-space: pre;"></span><pre name="code" class="sql" style="font-family: Arial; color: rgb(51, 51, 51); font-size: 14px; line-height: 26px;"><span> </span>SELECT id,name,borndata FROM info_user WHERE name LIKE '%h';
<span style="color: rgb(51, 51, 51); font-family: monospace; font-size: 14px; line-height: 26px; white-space: pre;"> </span><span style="color: rgb(51, 51, 51); font-family: monospace; font-size: 14px; line-height: 26px; white-space: pre; background-color: rgb(240, 240, 240);">SELECT id,name,borndata FROM info_user WHERE name LIKE 'j%n';</span>
<span> </span>SELECT id,name,borndata FROM info_user WHERE name LIKE '%e%'; <span style="font-family: Arial;"> </span>
<span style="font-family: Arial;"><span style="white-space:pre"> </span>注意:</span>
<span style="font-family: Arial;"><span style="white-space:pre"> </span>1. %可以代表0、1、多个字符 </span>
<span style="font-family: Arial;"> 2. 注意尾空格:如果字段值最后有个空格,那么使用第二句查询是没有结果的。</span>
<span style="font-family: Arial;"><span style="white-space:pre"> </span>3. 对于 like ‘%’ 来说,字段值为null是搜索不出的。</span>
<span style="font-family: Arial;">
</span>
<span style="font-family: Arial;">4.2 _ 通配符</span>
<span style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="font-family:Arial;"> </span></span><span style="font-family: monospace; color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; white-space: pre; background-color: rgb(240, 240, 240);">SELECT id,name,borndata FROM info_user WHERE name LIKE 'Luc_';</span>
<pre name="code" class="sql" style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; font-family: Arial;"><span> </span>注意:
<pre name="code" class="sql" style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; font-family: Arial;"><span> </span>_ 只可以代表 单个字符。
SELECT id,name,borndata FROM info_user WHERE name LIKE 'j%n';