Tags
MySQL , INSTR
Asked 1 years ago
31 May 2022
Views 244
kord

kord posted

what is the use of INSTR in MySQL?

what is INSTR in MySQL ? how to use function INSTR in MySQL?
ruby-rails

ruby-rails
answered Feb 27 '23 00:00

The INSTR function in MySQL is used to search for a substring within a string and return the position of the first occurrence of the substring .

The syntax for the INSTR function is as follows:


INSTR(str,substr)

Where str is the string to be searched, and substr is the substring to be searched for.

The function returns an integer value that indicates the position of the first occurrence of the substring within the string. If the substring is not found, the function returns 0.

Here's an example usage of the INSTR function:


SELECT INSTR('Array Overflow', 'Overflow');


Output:

7

In this example, the INSTR function is used to search for the substring 'Overflow' within the string 'Array Overflow'. Since the substring is found starting at position 8, the function returns the value 8.

The INSTR function can be useful in many scenarios, such as searching for a specific substring within a longer string, or determining the position of a character within a string for further processing.
Post Answer