Updated on 2026-11-06 GMT+08:00

find_in_set

The find_in_set function is used to find the position of string str1 in the comma (,) separated string str2, counting from 1.

Syntax

find_in_set(string , string )

Parameters

Parameter

Mandatory

Type

Description

str1

Yes

STRING

The string to find.

str2

Yes

STRING

A string separated by commas (`,`).

Return Values

Returns a value of type BIGINT.

  • When str1 cannot be matched in str2 or str1 contains a comma (,), 0 is returned.
  • When str1 or str2 is NULL, NULL is returned.

Example Code

  • Find the position of string ab in the string abc,123,ab,c. The command example is as follows.

    Returns 3.

    select find_in_set('ab', 'abc,123,ab,c');
  • Find the position of string hi in the string abc,123,ab,c. The command example is as follows.
    Returns 0.
    select find_in_set('hi', 'abc,123,ab,c');
  • Any input parameter is NULL. The command example is as follows.

    Returns NULL.

    select find_in_set(null, 'abc,123,ab,c');