How can I count number of occurrences of the character -
in a varchar2 string?
Example:
select XXX(\'123-345-566\', \'-\') from dual;
--
here is a solution that will function for both characters and substrings:
select (length('a') - nvl(length(replace('a','b')),0)) / length('b')
from dual
where a is the string in which you search the occurrence of b
have a nice day!
Here's an idea: try replacing everything that is not a dash char with empty string. Then count how many dashes remained.
select length(regexp_replace('123-345-566', '[^-]', '')) from dual
REGEXP_COUNT should do the trick:
select REGEXP_COUNT('123-345-566', '-') from dual;