totn MariaDB Functions

MariaDB: FIND_IN_SET Function

This MariaDB tutorial explains how to use the MariaDB FIND_IN_SET function with syntax and examples.

Description

The MariaDB FIND_IN_SET function returns the position of a string in a comma-delimited string list.

Syntax

The syntax for the FIND_IN_SET function in MariaDB is:

FIND_IN_SET( string, string_list )

Parameters or Arguments

string
The string to find.
string_list
A list of string values separated by commas that is to be searched.

Note

  • If string is not found in string_list, the FIND_IN_SET function will return 0.
  • If string is NULL, the FIND_IN_SET function will return NULL.
  • If string_list is an empty string, the FIND_IN_SET function will return 0.
  • If string_list is NULL, the FIND_IN_SET function will return NULL.

Applies To

The FIND_IN_SET function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB FIND_IN_SET function examples and explore how to use the FIND_IN_SET function in MariaDB.

For example:

SELECT FIND_IN_SET('On', 'Tech,On,The,Net');
Result: 2

SELECT FIND_IN_SET('ON', 'Tech,On,The,Net');
Result: 2

SELECT FIND_IN_SET(3,'1,2,3');
Result: 3

SELECT FIND_IN_SET('T', 'T,C,B');
Result: 1

SELECT FIND_IN_SET('Check', 'Tech,On,The,Net');
Result: 0

SELECT FIND_IN_SET('A', '');
Result: 0

SELECT FIND_IN_SET(NULL, 'a,b,c');
Result: NULL

SELECT FIND_IN_SET('a', NULL);
Result: NULL