SUBSTRING(ansi)

From SQLZOO
Revision as of 14:10, 16 July 2012 by Connor (Talk | contribs) (Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>SUBSTRING(s FROM i FOR j)</th></tr> <tr><td align='center'>'''Engine'''</td><td align='ce...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Compatibility
SUBSTRING(s FROM i FOR j)
EngineOKAlternative
ingresYesSUBSTRING(s,i,j)
oracleNoSUBSTRING(s,i,j)
postgresYesSUBSTRING(s,i,j)
sqlserverNoSUBSTR(s,i,j)

SUBSTRING (ansi)

SUBSTRING allows you to extract part of a string.

   SUBSTRING('Hello world' FROM 2 FOR 3) -> 'llo'    

In this example you put the region and the name together for each country.

SELECT name,
       SUBSTR(name, 2, 5)
  FROM bbc
SELECT name,
       SUBSTRING(name, 2, 5)
  FROM bbc
SELECT name,
       SUBSTRING(name FROM 2 FOR 5)
  FROM bbc

See also