Skip to content

REGEXP_INSTR

REGEXP_INSTR(string, pattern, start, occurrence, return_end, match_param)

Section titled “REGEXP_INSTR(string, pattern, start, occurrence, return_end, match_param)”
  • string: This parameter represents the string in which the search is performed. It could be any of the data type CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.
  • pattern: This denotes the regular expression to be searched. For any character other than a multibyte character, this has to be a VARCHAR2 expression.
  • start: Defines the position in the string where the search is to begin. It is 1 by default. If the value is negative, the function counts back from the end of the string and begins the search.
  • occurrence: Specifies which occurrence of the pattern the function should search for. By default, it is set to 1, meaning the function will look for the first instance of the pattern.
  • return_end: It controls the value that the function returns. When set to 0, it returns the beginning position of the match. When set to 1, it returns the position of the character following the match. Default is 0.
  • match_param: A string of characters allowing control over the match behavior. It can include ‘c’ for case-sensitive matching, ‘n’ for allowing match-any-character operator to match the newline character, ‘m’ for treating the source string as multiple lines, ‘x’ for ignoring whitespace characters, ‘i’ for case-insensitive matching.
SELECT REGEXP_INSTR('Oracle Example', 'a') FROM dual;
2

The REGEXP_INSTR function in this example is used to return the position of the first occurrence of ‘a’ in the string ‘Oracle Example’. As indexing starts from 1, and ‘a’ is the second letter in the phrase, the output is ‘2’.