Ula Krukar Ula Krukar - 7 months ago 18
SQL Question

How to count the number of occurrences of a character in an Oracle varchar value?

How can I count number of occurrences of the character

-
in a varchar2 string?

Example:


select XXX('123-345-566', '-') from dual;
----------------------------------------
2

Answer

Here you go:

select length('123-345-566') - length(replace('123-345-566','-',null)) 
from dual;