In this guide, we will explain how to use the MySQL POSITION function with syntax and examples.
Description
The MySQL POSITION function returns the location of a substring in a string.
Syntax
The syntax for the POSITION function in MySQL is:
POSITION( substring IN string )
Parameters or Arguments
substring
The substring to search for in string.
string
The string to search.
Note
- The first position in string is 1.
- If substring is not found in string, then the POSITION function will return 0.
- When searching for the location of a substring in a string, the POSITION function does not perform a case-sensitive search.
- The POSITION function is a synonym for the LOCATE function.
Applies To
The POSITION function can be used in the following versions of :
- 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 POSITION function examples and explore how to use the POSITION function.
For example:
mysql> SELECT POSITION('A' IN 'Ad gl o b'); Result: 1 mysql> SELECT POSITION('a' IN 'Ad gl o b'); Result: 1 mysql> SELECT POSITION('d' IN 'Ad gl o b'); Result: 2 mysql> SELECT POSITION('l' IN 'adglob.in'); Result: 4 mysql> SELECT POSITION('ob' IN 'adglob.in'); Result: 5 mysql> SELECT POSITION('Z' IN 'adglob.in'); Result: 0
Next Topic : Click Here
Pingback: MySQL: MID Function | Adglob Infosystem Pvt Ltd