mysql是否包含特定字符_MySQL判断是否包含某个字符串

论坛 期权论坛 脚本     
已经匿名di用户   2022-7-2 21:59   1102   0

like语句

s.e.l.e.c.t * from `table` w.h.e.r.e `condition` like `%keyword%';

事实上,可以使用 locate(position) 和 instr 这两个函数来代替

一、locate语句

s.e.l.e.c.t * from `table` w.h.e.r.e locate(‘keyword’, `condition`)>0;

二、或是 locate 的別名 position

position语句

s.e.l.e.c.t * from `table` w.h.e.r.e position(‘keyword’ in `condition`);

三、instr语句

s.e.l.e.c.t * from `table` w.h.e.r.e instr(`condition`, ‘keyword’)>0;

locate、position 和 instr 的差別只是参数的位置不同,同时locate 多一个起始位置的参数外,两者是一样的。

四、find_in_set函数

find_in_set(str1,str2) 返回str2中str1所在的位置索引,其中str2必须以","分割开。

例如test表结构idname

1zhangsan,lisi

2wangwu,liuliu

查询name中含有zhangsan的

s.e.l.e.c.t * from test w.h.e.r.e find_in_set('zhangsan',name);

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP