Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

MySQL Instr String

by suresh

How to write instr in MySQL with example?. The MySQL Instr string is one of the String Functions, which returns the position of the first occurrence of a specified substring from a given string.

MySQL Instr String Syntax

The basic syntax of the Instr in MySQL is as shown below.

SELECT INSRT (String, Sub_String) FROM Source
  • String: A valid string or expression in which you want to look.
  • Sub_String: String that you are looking for.

The Instr function in MySQL returns the index position of the first occurrence of a Sub_String in a String. If then Sub_String is not found, it returns 0 as output.

MySQL Instr String Example 1

The following query shows multiple ways to use this string Instr function using different string values.

SELECT INSTR('TutorialGateway', 'a') AS Instr1;

SELECT INSTR('MySQL Tutorial at Tutorial Gateway', 'Tutorial') AS Instr2;

SELECT INSTR('We are abc working at abc company', 'abc') AS Instr3;

SELECT INSTR('We are abc working at abc company', 'MySQL') AS Instr4;

OUTPUT

MySQL Instr String 1

ANALYSIS

Within this string function example, the below statement, we used Instr to find the index position of the first occurrence of a

SELECT INSTR('TutorialGateway', 'a') AS Instr1;

In the last MySQL statement, we are looking for a substring that does not exist.

SELECT INSTR('We are abc working at abc company', 'MySQL') AS Instr4;

Instr String Example 2

The MySQL String Instr function also allows you to write the index position from column values too. To demonstrate this string function, We are going to use the below-shown data.

MySQL Instr String 2

In this example, we are going to use this string Instr function to find the index position of High word in the Education column.

-- MySQL String Instr Function Example
USE `mysql tutorial`;
SELECT  EmpID,
		FirstName,
        LastName,
        Education,
        INSTR(Education, 'High') AS InsrtFunction,
        Occupation,
		YearlyIncome,
        Sales
FROM employee;

OUTPUT

MySQL Instr String 3

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy