Open In App

InStr() and InstrRev() Function in MS Access

1. InStr() Function :
The InStr() Function returns the position of a string in another string. It always returns the first occurrence of the string. It works not case sensitive. It returns 0 if the string2 is not found in string1 or string1 is null or the parameter starts in the function is greater than length of string1 and it returns null if string1 is null and if the length of string2 is zero then it returns value of start parameter.

Syntax –



InStr(start, string1, string2, compare)

Parameters –

Possible Values –



Return – It returns 0, 1 or null.

Example –

SELECT InStr("geeksforgeeks", "f") 
AS MatchPosition;

Output –

MatchPosition
6

Example –

SELECT InStr("DSA self paced", "a") 
AS MatchPosition;

Output –

MatchPosition
3


2. InstrRev() Function :
The InstrRev() Function function works like Instr() function but it returns position of the first occurrence of a string in another, from the end of string. The start parameter in this default -1.

Syntax :

InstrRev(string1, string2, start, compare)

Example –

SELECT InStrRev("geeksforgeeks", "k") 
AS MatchPosition;

Output –

MatchPosition
12

Example –

SELECT InStrRev("gfg", "k") 
AS MatchPosition;

Output –

MatchPosition
0
Article Tags :
SQL