O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)
    

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required