Oracle REGEXP Functions
Explore advanced text matching with Oracle REGEXP functions.
The Oracle REGEXP_ functions are used to search and manipulate strings using simple string patterns. These functions can be used in SQL and PL/SQL statements. The expression is made up of special characters, which have their own meaning. This expression is then used in a regular expression function, and then the result is used in your query.
Why Use Regular Expressions?
There are several string operations in Oracle SQL that let you perform some comparisons. For example, you can use UPPER to find upper case values, and you can use LIKE along with the wildcard characters %, _ and * to find specific values. These functions are insufficient for more intricate inspections, though. Regular expressions can be used to:
Check phone number formats
Check email address formats
Check URLs match a specific format
Check any other type of string value to see if it matches the desired format
There are a few functions in Oracle SQL that can be used with regular expressions:
REGEXP_LIKE
REGEXP_INSTR
REGEXP_REPLACE
REGEXP_SUBSTR
REGEXP_COUNT (added in Oracle 11g)
Oracle REGEXP_LIKE Function
The REGEXP_LIKE function looks for a certain pattern in a column. It is utilised in a WHERE clause to determine if the row should be included in the result set. The syntax for the REGEXP_LIKE function is
REGEXP_LIKE (source_string, pattern [, match_parameter] )Where:
source_string (mandatory): The value that is searched in. It can be any data type of CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.
pattern (mandatory): This is the regular expression that you provide. It can be up to 512 bytes.
match_parameter (optional): This allows you to change the default matching behaviour of the function, which can be one or more of below:
“i”: case-insensitive matching
“c”: case-sensitive matching
