码迷,mamicode.com
首页 > 数据库 > 详细

MySQL中like的使用方法

时间:2015-03-07 15:27:48      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

Like的运用场合主要在模糊查询的时候,一般以查询字符串居多,这里据一些例子来说他的一般用法:

《1》查询name字段中包含有“明”字的:例 select * from table1 where name like ‘%明%’
(这里不能使用*来代替,一般在使用0个或者任意个字符构成的字符串的时候最好使用%)
《2》只在首或尾% 和 * 两者都可以使用: 例 select * from table1 where name like ‘%明’
或:select * from table1 where name like ‘*明’
《3》如果在头尾同时使用的话,就必须要使用% :例 select * from table1 where name like ‘%[a-z]%’
《4》查询name字段中含有数字的:select * from table1 where name like ‘%[0-9]%’
《5》查询name字段中含有小写字母的:select * from table1 where name like ‘%[a-z]%’
《6》查询name字段中不含有数字的:select * from table1 where name like ‘%[!0-9]%’
补充一点,?或者_表示单个字符

MySQL中like的使用方法

标签:

原文地址:http://www.cnblogs.com/xiaocao1434/p/XiaoCao_MySQL.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!