find_in_set(str,strlist)是MySQL的一个字符串函数。此方法返回子字符串第一次在字符串出现的位置,其中字符串用逗号分隔。
语法
select find_in_set(str, 'str1, str2,...');
参数
str: 要找的字符串
'str1, str2...':逗号分割的字符串
示例 1
Select find_in_set('a','b,c,d,a');
输出:
mysql> Select find_in_set('a','b,c,d,a');
+----------------------------+
| find_in_set('a','b,c,d,a') |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)
示例 2
Select find_in_set(4,'1,2,3,5,4,6');
输出:
mysql> Select find_in_set(4,'1,2,3,5,4,6');
+------------------------------+
| find_in_set(4,'1,2,3,5,4,6') |
+------------------------------+
| 5 |
+------------------------------+
1 row in set (0.00 sec)
示例 3
Select find_in_set(12,'1,2,3,4,6');
输出:
mysql> Select find_in_set(12,'1,2,3,4,6');
+-----------------------------+
| find_in_set(12,'1,2,3,4,6') |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (0.00 sec)