Professional Documents
Culture Documents
docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/REGEXP_COUNT.html
pattern is the regular expression. It is usually a text literal and can be of any of the
data types CHAR , VARCHAR2 , NCHAR , or NVARCHAR2 . It can contain up to 512
bytes. If the data type of pattern is different from the data type of source_char ,
then Oracle Database converts pattern to the data type of source_char .
1/6
match_param is a character expression of the data type VARCHAR2 or CHAR
that lets you change the default matching behavior of the condition.
The value of match_param can include one or more of the following characters:
'm' treats the source string as multiple lines. Oracle interprets the caret (
^ ) and dollar sign ( $ ) as the start and end, respectively, of any line
anywhere in the source string, rather than only at the start or end of the
entire source string. If you omit this parameter, then Oracle treats the source
string as a single line.
The default case and accent sensitivity are determined by the determined
collation of the REGEXP_COUNT function.
See Also:
Examples
The following example shows that subexpressions parentheses in pattern are ignored:
2/6
SELECT REGEXP_COUNT('123123123123123', '(12)3', 1, 'i') REGEXP_COUNT
FROM DUAL;
REGEXP_COUNT
------------
5
In the following example, the function begins to evaluate the source string at the third
character, so skips over the first occurrence of pattern:
COUNT
----------
3
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters:
REGEXP_COUNT('ABC123','[A-Z]') REGEXP_COUNT('A1B2C3','[A-Z]')
------------------------------ ------------------------------
3 3
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by a single digit number:
REGEXP_COUNT('ABC123','[A-Z][0-9]') REGEXP_COUNT('A1B2C3','[A-Z][0-9]')
----------------------------------- -----------------------------------
1 3
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by a single digit number
only at the beginning of the string:
REGEXP_COUNT('ABC123','^[A-Z][0-9]') REGEXP_COUNT('A1B2C3','^[A-Z][0-9]')
------------------------------------ ------------------------------------
0 1
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by two digits of number
only contained within the string:
3/6
select regexp_count('ABC123', '[A-Z][0-9]{2}'), regexp_count('A1B2C3', '[A-Z][0-9]{2}') from dual;
REGEXP_COUNT('ABC123','[A-Z][0-9]{2}') REGEXP_COUNT('A1B2C3','[A-Z][0-9]{2}')
-------------------------------------- --------------------------------------
1 0
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by a single digit number
within the first two occurrences from the beginning of the string:
REGEXP_COUNT('ABC123','([A-Z][0-9]){2}') REGEXP_COUNT('A1B2C3','([A-Z][0-9]){2}')
---------------------------------------- ----------------------------------------
0 1
Live SQL:
View and run related examples on Oracle Live SQL at REGEXP_COUNT simple matching
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters:
MATCH_CHAR_ABC_COUNT MATCH_CHAR_ABC_COUNT
-------------------- --------------------
3 3
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by a single digit number:
MATCH_STRING_C1_COUNT MATCH_STRINGS_A1_B2_C3_COUNT
--------------------- ----------------------------
1 3
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by a single digit number
only at the beginning of the string:
CHAR_NUM_LIKE_A1_AT_START CHAR_NUM_LIKE_A1_AT_START
------------------------- -------------------------
0 1
4/6
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by two digits of number
only contained within the string:
CHAR_NUM_LIKE_A12_ANYWHERE CHAR_NUM_LIKE_A12_ANYWHERE
-------------------------- --------------------------
1 1
In the following example, REGEXP_COUNT validates the supplied string for the given
pattern and returns the number of alphabetic letters followed by a single digit number
within the first two occurrences from the beginning of the string:
CHAR_NUM_WITHIN_2_PLACES CHAR_NUM_WITHIN_2_PLACES
------------------------ ------------------------
0 1
Live SQL:
View and run related examples on Oracle Live SQL at REGEXP_COUNT advanced
matching
The following statements create a table regexp_temp and insert values into it:
In the following example, the statement queries the employee name column and
searches for the lowercase of character ‘E’:
EMPNAME CASE_SENSITIVE_E
-------------------- ----------------
John Doe 1
Jane Doe 2
In the following example, the statement queries the employee name column and
searches for the lowercase of character ‘O’:
5/6
SELECT empName, REGEXP_COUNT(empName, 'o', 1, 'c') "CASE_SENSITIVE_O" From regexp_temp;
EMPNAME CASE_SENSITIVE_O
-------------------- ----------------
John Doe 2
Jane Doe 1
In the following example, the statement queries the employee name column and
searches for the lowercase or uppercase of character ‘E’:
EMPNAME CASE_INSENSITIVE_E
-------------------- ------------------
John Doe 1
Jane Doe 2
In the following example, the statement queries the employee name column and
searches for the lowercase of string ‘DO’:
EMPNAME CASE_INSENSITIVE_STRING
-------------------- -----------------------
John Doe 1
Jane Doe 1
In the following example, the statement queries the employee name column and
searches for the lowercase or uppercase of string ‘AN’:
EMPNAME CASE_SENSITIVE_STRING
-------------------- ---------------------
John Doe 0
Jane Doe 1
Live SQL:
View and run related examples on Oracle Live SQL at REGEXP_COUNT case-sensitive
matching
6/6