top of page

How to count occurrences in string in PLSQL

  • Writer: Rumesh Aponso (RMAX)
    Rumesh Aponso (RMAX)
  • Nov 7, 2024
  • 1 min read

Updated: Nov 22, 2024

Example 1:

SELECT REGEXP_COUNT ('ö', 'ö|e|i|o|u', 1, 'i') FROM DUAL;

SELECT REGEXP_COUNT ('rma_023ößö', 'a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|ö|ä|ü|ß|0|1|2|3|4|5|6|7|8|9|_', 1, 'i')
FROM   DUAL;

SELECT REGEXP_COUNT ('TechOnTheNet is a great resource', 'T') FROM DUAL;
ree

Example 2:

DECLARE
   count_      VARCHAR2(100);
   log_data_   CLOB;
BEGIN
   log_data_ := 'The REGEXP_LIKE condition uses the input character set to evaluate strings.
If you specify match_parameter values that conflict, the REGEXP_LIKE condition will use the last value to break the conflict.
If the match_parameter is omitted, the REGEXP_LIKE condition will use the case-sensitivity as determined by the NLS_SORT parameter.';
 
   count_ := REGEXP_COUNT(log_data_, 'REGEXP_LIKE');
 
   Dbms_Output.Put_Line(log_data_);
   Dbms_Output.Put_Line('Count: ' || count_);
END;

Related Links:

Comments


Copyright © 2025 RMAXOneNote

  • Online CV
  • LinkedIn
  • Youtube
  • GitHub
  • Blogger
bottom of page