Preamble
Oracle/PLSQL REGEXP_COUNT function calculates the number of occurrences of the template in the string. This function, introduced in Oracle 11g, allows you to count the number of times a substring occurs in a string using a regular expression pattern matching.
Oracle/PLSQL syntax REGEXP_COUNT function
REGEXP_COUNT( string_id, pattern_id [, start_position_id [, atch_parameter_id ] ] )
Parameters and arguments
- string_id – A search line. String can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB or NCLOB.
- pattern_id – Template. Regular expression for comparison. It can be a combination of the following values:
| Meaning | Description |
| ^ | Corresponds to the beginning of the line. When using match_parameter with m, corresponds to the beginning of the string anywhere within the expression. |
| $ | Corresponds to the end of the line. When using match_parameter with m, it corresponds to the end of the string anywhere within the expression. |
| * | Corresponds to zero or more occurrences. |
| + | Corresponds to one or more occurrences. |
| ? | Corresponds to zero or one entry. |
| . | Corresponds to any character except NULL. |
| | | Used as “OR” to specify more than one alternative. |
| [ ] | It is used to specify a list of matches where you try to match any of the characters in the list. |
| [^ ] | It is used to specify a nonmatching list where you try to match any character except for those on the list. |
| ( ) | Used for group expressions as subexpressions. |
| {m} | Corresponds m times. |
| {m,} | Matching at least m times. |
| {m,n} | Matching at least m times, but not more than n times. |
| \n | n is a number between 1 and 9. It corresponds to the n-th subexpression located in ( ) before \n. |
| [..] | Corresponds to a single element mappings that can be more than one character. |
| [::] | Meets the symbol class. |
| [==] | Corresponds to the class of equivalence |
| \d | Corresponds to the digital symbol. |
| \D | Corresponds to a non-digital symbol. |
| \w | Corresponds to the text symbol. |
| \W | Corresponds to a non-text symbol. |
| \s | Corresponds to the space character. |
| \S | Doesn’t match the space character. |
| \A | Corresponds to the beginning of a line or corresponds to the end of a line before a new line character. |
| \Z | Corresponds to the end of the line. |
| *? | Corresponds to the previous pattern of zero or more occurrences. |
| +? | One or more entries correspond to the previous template. |
| ?? | Corresponds to the previous zero or one entry pattern. |
| {n}? | Corresponds to the previous template n times. |
| {n,}? | Corresponds to the previous template at least n times. |
| {n,m}? | Corresponds to the previous template at least n times, but not more than m times. |
- start_position_id – It’s optional. This is the position on the line from which the search will begin. If this option is omitted, by default it is 1, which is the first position in the line.
- match_parameter_id – It’s optional. It allows you to change the matching behavior for the function REGEXP_COUNT. This can be a combination of the following values:
| Meaning | Description |
| ‘c’ | Performs register-sensitive alignment. |
| ‘i’ | Performs case insensitive alignment. |
| ‘n’ | Allows a character period (.) to match the character of a new string. By default, the metasymic period. |
| ‘m’ | The expression assumes that there are several lines where ^ is the beginning of a line and $ is the end of a line, regardless of the position of these characters in the expression. By default, the expression is assumed to be on the same line. |
| ‘x’ | The symbols of spaces are ignored. By default, the space characters are the same as any other character. |
The function REGEXP_COUNT returns a numerical value.
If there are conflicting values for match_parameter, the REGEXP_COUNT function will use the last value.
If the REGEXP_COUNT function does not detect any pattern occurrence, it will return 0.
REGEXP_COUNT function in the following versions of Oracle / PLSQL
Oracle 12c, Oracle 11g
Example of a single symbol match
Let’s look at the simplest example. Let’s calculate how many times the ‘a’ character appears in a string.
For instance:
SELECT REGEXP_COUNT ('Aller Anfang ist schwer', 'a')
FROM dual;
-Result: 1
This example will return 1 because it counts the number of ‘a’ occurrences in a string. Since we haven’t specified the match_parameter value, the REGEXP_COUNT function will perform a case sensitive search, which means that the ‘A’ character will not be included into the count.
If we wanted to include both ‘a’ and ‘A’ in our result and perform a case insensitive search, we would change our query as follows:
SELECT REGEXP_COUNT ('Aller Anfang ist schwer', 'a', 1, 'i')
FROM dual;
-Result: 3
Now, since we have provided start_position = 1 and match_parameter = ‘i’, the query will return 3 as a result. This time the values ‘a’ and ‘A’ will be included into the result.
If we wanted to count the number of ‘a’ in a column, we could try something like this:
SELECT REGEXP_COUNT (last_name, 'a', 1, 'i') AS total
FROM contacts;
This query will count the number of ‘a’ or ‘A’ values in the last_name field from the contacts table.
Example of a multi-character match
Let’s see how we will use the REGEXP_COUNT function to match a multi-character pattern.
For example:
SELECT REGEXP_COUNT ('Gute Saat, gute Ernte', 'gute', 1, 'i')
FROM dual;
-Result: 2
In this example, we will return the number of times the word ‘gute’ appears in the string. The search is case-insensitive, so the result is 2 entries.
SELECT REGEXP_COUNT ('Gute Saat, gute Ernte', 'gute', 5, 'i')
FROM dual;
-Result: 1
In this example, the number of times the word ‘gute’ appears in the string starting from position 5 will be returned. In this case the result is 1 because it will skip the first 4 characters in the string before searching for the template.
Now let’s see how we are going to use the REGEXP_COUNT function with the table column and search for several characters. For example:
SELECT REGEXP_COUNT (other_comments, 'the', 1, 'i')
FROM contacts;
-Result: 3
In this example, we will count the number of times “the” appears in the other_comments field in the contacts table.
This is an example of comparing several alternatives
The next example we’ll look at involves using the | pattern. | pattern is used as an “OR” to specify multiple alternatives. For example:
SELECT REGEXP_COUNT ('AeroSmith', 'a|e|i|o|u').
FROM dual;
-Result: 3
This example will return 3 because it counts the number of vowels (a, e, i, o or u) in the string ‘AeroSmith’. Since we didn’t specify a match_parameter value, the REGEXP_COUNT function will perform case sensitive searches, which means that ‘A’ in ‘AeroSmith’ will not be counted.
We could modify our query to perform a case-insensitive search as follows:
SELECT REGEXP_COUNT ('AeroSmith', 'a|e|i|o|u', 1, 'i')
FROM dual;
-Result: 4
Now, since we have specified start_position = 1 and match_parameter = ‘i’, the query will return as result 4. This time ‘A’ in ‘AeroSmith’ will be included into the score.
Now let’s see how we will use this function with the column.
So, suppose we have a contact table with the following data:
| contact_id | last_name |
| 1000 | AeroSmith |
| 2000 | Joy |
| 3000 | Scorpions |
Now let’s start the next request:
SELECT contact_id, last_name, REGEXP_COUNT (last_name, 'a|e|i|o|u', 1, 'i') AS total
FROM contacts;
The results to be returned by the request:
| contact_id | last_name | total |
| 1000 | AeroSmith | 4 |
| 2000 | Joy | 1 |
| 3000 | Scorpions | 3 |
About Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
What Drives Growth in Fashion Tech: Enteros AI SQL, Database Performance Management, and RevOps Intelligence
- 3 March 2026
- Database Performance Management
Introduction The fashion industry has evolved into a digital-first, data-intensive ecosystem. Global apparel brands, luxury houses, direct-to-consumer startups, and fast-fashion giants now compete not just on design and brand—but on digital performance. E-commerce platforms must handle flash sales without crashing. Omnichannel inventory systems must synchronize in real time. AI-driven personalization engines must respond instantly. Pricing … Continue reading “What Drives Growth in Fashion Tech: Enteros AI SQL, Database Performance Management, and RevOps Intelligence”
Who Should Use Enteros for Financial Performance Optimization and Cloud Cost Governance?
Introduction The financial sector is under relentless pressure to grow—without increasing risk, cost, or operational complexity. Digital-first banks are reshaping customer expectations. Capital markets firms demand real-time analytics. Insurers are automating underwriting and claims. Fintech startups scale at cloud speed. Meanwhile, regulatory requirements intensify, margins tighten, and infrastructure costs rise. At the center of all … Continue reading “Who Should Use Enteros for Financial Performance Optimization and Cloud Cost Governance?”
How to Accelerate Banking Growth with Enteros Performance Management and Generative AI
- 2 March 2026
- Database Performance Management
Introduction The banking industry is evolving at unprecedented speed. Digital-first challengers are redefining customer expectations. Legacy institutions are modernizing core systems. Real-time payments, open banking frameworks, AI-driven fraud detection, and personalized financial services are now standard. But beneath every digital innovation lies a critical truth: Banking growth depends on performance. Read more”Indian Country” highlights Enteros … Continue reading “How to Accelerate Banking Growth with Enteros Performance Management and Generative AI”
What Drives Profitability in Fashion Tech: AI SQL, Cost Attribution, and Database Governance with Enteros
Introduction The fashion industry has transformed into a digital-first ecosystem. Global apparel brands, luxury retailers, direct-to-consumer startups, and fast-fashion giants now rely on sophisticated technology stacks to power: E-commerce platforms Omnichannel inventory systems Read more”Indian Country” highlights Enteros and its database performance management platform *Real-time pricing engines Demand forecasting models Supply chain visibility tools Read … Continue reading “What Drives Profitability in Fashion Tech: AI SQL, Cost Attribution, and Database Governance with Enteros”