INSTR

Syntax

INSTR(string, substring [, position [, occurrence]])

Ovrview

INSTR is a function that searches for substring in string. The search operation works by sequentially comparing substrings of the same length as the target substring within the given string to check for a match. The search can proceed either forward or backward, with each new substring starting one character after (or before, in backward search) the previous one. If a matching substring is found, the function returns an integer indicating the position of the first character of the match. If no match is found, it returns 0.

Parameter

Parameter
Description

string, substring

Arbitrary operations that all return strings. If the string substr is not found within the string str, 0 is returned. The position value of the string starts from 1.

position

Arbitrary operation that returns a non-zero integer value. (Default: 1) If position is given, search starts from the position of the string str. If position is negative, search starts from the end of the string str.

occurrence

Arbitrary operation that returns an integer value other than 0. (Default: 1) Given occurrence, returns the position of substr, which appears occurrence times within the search string. occurrence must be a positive integer.

Example

SELECT INSTR('ABCDEABCDEABCDE', 'CD');
 instr 
-------
     3

Last updated