Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

POSITION

Example

Locate the position of “3” within the string “W3Schools.com” and return its index.

SELECT POSITION(“3” IN “W3Schools.com”AS MatchPosition; 

Definition and Usage

The POSITION() function provides the position of the first occurrence of a substring in a string.

If the substring isn’t found within the original string, this function returns 0.

This function conducts a case-insensitive search.

Note: that the LOCATE() function is equivalent to the POSITION() function.

Syntax

POSITION(substring IN string)

Parameter Values

Parameter

Description

substring

Input required: The substring to be searched for within the string.

string

Input required: The original string in which the search will be performed.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Look for “COM” within the string “W3Schools.com” and provide its position.

SELECT POSITION(“COM” IN “W3Schools.com”AS MatchPosition; 

Example

Find the position of “a” within the CustomerName column and return its index.

SELECT POSITION(“a” IN CustomerName)
FROM Customers;