The MULTI_SEARCH_ALL_POSITIONS function searches for multiple substrings in a string in batch. Returns an array containing the position of the first occurrence of each substring. The search is case-sensitive.
MULTI_SEARCH_ALL_POSITIONS(<haystack>, <needles>)
| Parameter | Description |
|---|---|
<haystack> | The target string to search in. Type: VARCHAR |
<needles> | Array containing multiple substrings to search for. Type: ARRAY |
Returns ARRAY type, where the i-th element in the array represents the position of the first occurrence of the i-th substring in <needles> within <haystack>.
Special cases:
<haystack> or <needles> is NULL, returns NULLSELECT multi_search_all_positions('Hello, World!', ['Hello', 'World']);
+----------------------------------------------------------+ | multi_search_all_positions('Hello, World!', ['Hello', 'World']) | +----------------------------------------------------------+ | [1, 8] | +----------------------------------------------------------+
SELECT multi_search_all_positions('Hello, World!', ['hello', '!', 'world']);
+----------------------------------------------------------------------+ | multi_search_all_positions('Hello, World!', ['hello', '!', 'world']) | +----------------------------------------------------------------------+ | [0, 13, 0] | +----------------------------------------------------------------------+
SELECT multi_search_all_positions('Hello, World!', ['Hello', '!', 'xyz']);
+--------------------------------------------------------------------+ | multi_search_all_positions('Hello, World!', ['Hello', '!', 'xyz']) | +--------------------------------------------------------------------+ | [1, 13, 0] | +--------------------------------------------------------------------+
SELECT multi_search_all_positions('Hello', []);
+------------------------------------------+ | multi_search_all_positions('Hello', []) | +------------------------------------------+ | [] | +------------------------------------------+
SELECT multi_search_all_positions('ṭṛì ḍḍumai Hello', ['ṭṛì', 'Hello', 'test']);
+----------------------------------------------------------------------------------------+ | multi_search_all_positions('ṭṛì ḍḍumai Hello', ['ṭṛì', 'Hello', 'test']) | +----------------------------------------------------------------------------------------+ | [1, 21, 0] | +----------------------------------------------------------------------------------------+
MULTI_SEARCH,SEARCH,POSITIONS