INSTR

From SQLZOO
Revision as of 13:22, 16 July 2012 by Connor (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Compatibility
INSTR(s1, s2)
EngineOKAlternative
ingresNoPOSITION(s2 IN s1)
mysqlYes
oracleYes
postgresNoPOSITION(s2 IN s1)
sqlserverNoPATINDEX('%'+s2+'%',s1)

INSTR

INSTR(s1, s2) returns the character position of the substring s2 within the larger string s1. The first character is in position 1. If s2 does not occur in s1 it returns 0.

    INSTR('Hello world', 'll') -> 3 

In this example you get the hour from the datetime field whn.

SELECT name,
       POSITION('an' IN name)
  FROM bbc
SELECT name,
       PATINDEX('%an%', name)
  FROM bbc
 ORDER BY name
SELECT name,
       INSTR(name, 'an')
  FROM bbc

See also

Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense