Finding Substrings with POSITION()
Use the POSITION() function to locate a particular substring within a given string. The POSITION() function’s important characteristics are:
POSITION() returns an integer (≥0) that indicates the starting position of a substring’s first occurrence within a string.
If the string doesn’t contain the substring, POSITION() returns zero.
String comparisons may be case-insensitive or case-sensitive, depending on your DBMS; see the DBMS Tip in “Filtering Rows with WHERE” in Chapter 4.
The position of any substring within an empty string is zero.
If any argument is null, POSITION() returns null. (But see the Oracle exception in the DBMS Tip in this section.)
To find a substring:
- Type:
POSITION(substring IN string)
Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.