find_in_set
时间: 2023-09-03 21:15:27 浏览: 62
() 函数在 MySQL 中有什么作用?
找在使用 MySQL 的数据表中,某个字段的值是否在一个给定的集合中。
该函数的语法为:
```
FIND_IN_SET(string, string_set)
```
其中,string 指定要查询的值,string_set 指定要查询的集合。
返回值为:如果找到了指定的值,则返回它在集合中的位置;否则返回 0。
需要注意的是,如果 string_set 中的值用逗号分隔且带有空格,则在使用此函数时需要精确匹配空格。例如,如果 string_set 的值为 'apple, banana, orange',则要查询的值必须与其自身的格式完全匹配。如果要使用非精确匹配,则需要先将 string_set 中的值用逗号和空格分割开,再使用 FIND_IN_SET() 函数进行查询。
相关问题
FIND_IN_SET
`FIND_IN_SET` is a MySQL function that is used to search for a value within a comma-separated list. It returns the position of the value within the list, or 0 if it is not found. The syntax for using `FIND_IN_SET` is as follows:
```sql
FIND_IN_SET(value, list)
```
Here, `value` is the value to search for, and `list` is the comma-separated list of values.
For example, `FIND_IN_SET('apple', 'apple,banana,grape')` will return 1, as 'apple' is the first value in the list. On the other hand, `FIND_IN_SET('orange', 'apple,banana,grape')` will return 0, as 'orange' is not present in the list.
Is there anything else you would like to know?
SELECT * FROM t01_di_cust_info where 1=1 and ( FIND_IN_SET(1,KEY_INDUSTRIAL_CHAIN) AND FIND_IN_SET(3,KEY_INDUSTRIAL_CHAIN) )
根据提供的引用内容,SELECT语句中的FIND_IN_SET函数用于在字符串列表中查找指定的值。在这个例子中,FIND_IN_SET函数用于在KEY_INDUSTRIAL_CHAIN字段的值中查找1和3。如果找到了这两个值,则返回true,否则返回false。
以下是一个示例SELECT语句的演示:
```sql
SELECT * FROM t01_di_cust_info
WHERE 1=1
AND (FIND_IN_SET(1, KEY_INDUSTRIAL_CHAIN) AND FIND_IN_SET(3, KEY_INDUSTRIAL_CHAIN))
```
这个SELECT语句将返回t01_di_cust_info表中满足以下条件的所有行:
- 1和3都在KEY_INDUSTRIAL_CHAIN字段的值中出现。
阅读全文
相关推荐







