The POSITION function searches for a substring inside another string and returns its position when supported by the database.
Finding the location of a character or substring is useful when parsing structured text fields.
Find the position of the @ character in an email address.
SELECT
Email,
POSITION('@' IN Email) AS AtPosition
FROM Customers;
POSITION is useful for parsing email addresses, codes, identifiers, and structured text.
- POSITION searches for a substring.
- It returns the location of the match.
- It is useful for parsing text.
- Syntax varies between databases.
- It can be combined with SUBSTRING.
What does POSITION do?
POSITION finds the location of a substring within another string.
How can POSITION help parse an email?
It can locate the @ symbol so the email address can be split into different parts.