Ula Krukar Ula Krukar - 8 months ago 20
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;