September 2004
Intermediate to advanced
710 pages
24h 25m
English
POSITION
The POSITION function returns an integer that indicates the starting position of a string within the search string.
POSITION(string1INstring2)
The standard syntax for the POSITION function is
to return the first location of string1
within string2.
POSITION returns 0 if
string1 does not occur within
string2 and NULL if either argument is
NULL.
DB2’s equivalent function is POSSTR.
MySQL supports POSITION as defined in SQL2003.
Oracle’s equivalent function is called INSTR.
PostgreSQL supports POSITION as defined in SQL2003.
SQL Server has both CHARINDEX and PATINDEX. CHARINDEX and PATINDEX are very similar, except that PATINDEX allows the use of wildcard characters in the search criteria.
/* DB2 */SELECT POSSTR('bar', 'foobar');4 /* On MySQL */SELECT LOCATE('bar', 'foobar');4 /* On MySQL and PostgreSQL */SELECT POSITION('fu' IN 'snafhu');0 /* On Microsoft SQL Server */SELECT CHARINDEX( 'de', 'abcdefg' )GO4SELECT PATINDEX( '%fg', 'abcdefg' )GO6
Read now
Unlock full access