Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

InStr() and InstrRev() Function in MS Access

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 –

  • start : Optional (By default the position is 1)
  • String1 : Required (The string to be searched)
  • string2 : Required (The string to search for)
  • compare : Optional (Type of string comparison)

Possible Values –

  • -1 : Use the setting of Option Compare.
  • 0 : Binary comparison.
  • 1 : Textual comparison.
  • 2 : Comparison based on information in your database.

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
My Personal Notes arrow_drop_up
Last Updated : 28 Aug, 2020
Like Article
Save Article
Similar Reads