Skip to content

REGEXP_SUBSTR

REGEXP_SUBSTR(source_column, pattern [, start_position [, occurrence [, match_parameter]]])

Section titled “REGEXP_SUBSTR(source_column, pattern [, start_position [, occurrence [, match_parameter]]])”
  • source_column: The string column or expression where the regular expression will be searching.
  • pattern: The regular expression pattern that the function will search for in the source_column.
  • start_position: This optional parameter determines the position in the source column where the function should start looking for the pattern. By default, the start_position is 1.
  • occurrence: Another optional parameter, defining which occurrence of the pattern to search for. If omitted, the first occurrence is used.
  • match_parameter: This optional parameter enables various features related to case sensitivity, multi-line operations, and pattern matching. If omitted, the search is case-sensitive and single-line.
SELECT REGEXP_SUBSTR('123@456@789', '[^@]+', 1, 2) FROM dual;
456

The REGEXP_SUBSTR function in the example is used to extract a substring from a string. It utilizes regular expressions to specify the patterns to be extracted. The pattern here ’[^@]+’ tells the function to match any group of characters that are not ’@’. The following integers (1, 2) denote the start position and the occurrence, respectively. In this case, it starts from position 1 and returns the second occurrence of the pattern, which is ‘456’.