INSTR
Return the position of the first occurrence of a substring. This function locates a substring within a string and returns its index.
Syntax
INSTR(str,substr)Description
Returns the position of the first occurrence of substring substr in string str. This is the same as the two-argument form of LOCATE(), except that the order of the arguments is reversed.
INSTR() follows the collation of its arguments. With the default collation the search is case-insensitive. With a case-sensitive or binary collation, or a binary string, it is case-sensitive: INSTR(BINARY 'MariaDB','db') returns 0.
If any argument is NULL, returns NULL.
Examples
SELECT INSTR('foobarbar', 'bar');
+---------------------------+
| INSTR('foobarbar', 'bar') |
+---------------------------+
| 4 |
+---------------------------+
SELECT INSTR('My', 'Maria');
+----------------------+
| INSTR('My', 'Maria') |
+----------------------+
| 0 |
+----------------------+See Also
LOCATE() ; Returns the position of a string within a string
SUBSTRING_INDEX() ; Returns the substring from string before count occurrences of a delimiter
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?

