INDEX(a,b,p,s) 

INDEX(a,b,p,s) is an arithmetic function that determines the position of the substring specified in b within the character string a.

The parameter p is optional. If p is specified (p>=1), it defines the start position for the search for the substring b. If p is not specified, the search is started at position 1.

The parameter s is optional. If s is specified, it determines the number of searches for the substring b. If s is not specified, the search is carried out for the first occurrence.

 

Result of the INDEX(a,b,p,s) function

a, b character strings and b not less than s times substring of a

0

a character string and b empty character string

p

a,b,p or s is NULL value

NULL value

p or s is special NULL value

Error message

 

Model table: customer

The position of the character string ‘ar’ is to be determined in all customer surnames.

SELECT surname, INDEX(surname, 'ar') position_ar FROM customer

SURNAME

POSITION_AR

Barth

2

GIAG

0

Starke

3

Steger

0

Braun

0

Schwarz

5

Maler

0

Wenzel

0

Muschel

0

Rietz

0

Schulze

0

Tisch

0

Meyer

0

DATA_KG

0

Braun

0