MySQL: INSTR Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL INSTR Function

In this guide, we will explain how to use the MySQL INSTR function with syntax and examples.

Description

The MySQL INSTR function returns the location of a substring in a string.

Syntax

The syntax for the INSTR function in MySQL is:

INSTR( string, substring )

Parameters or Arguments

string

The string to search.

substring

The substring to search for in string.

Note

  • The first position in string is 1.
  • When finding the location of a substring in a string, the INSTR function does not perform case-sensitive search.
  • If substring is not found in string, then the INSTR function will return 0.

Applies To

The INSTR function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some MySQL INSTR function examples and explore how to use the INSTR function in MySQL.

For example:

mysql> SELECT INSTR('A D G L O B', 'A');
Result: 1

mysql> SELECT INSTR('A D G L O B', 'D');
Result: 3

mysql> SELECT INSTR('A D G L O B', 'G');
Result: 5

mysql> SELECT INSTR('adglob.in', 'l');
Result: 4

mysql> SELECT INSTR('adglob.in', 'in');
Result: 8

mysql> SELECT INSTR('adglob.in', 'Z');
Result: 0

Next Topic : Click Here

This Post Has One Comment

Leave a Reply