Ula Krukar Ula Krukar - 2 years ago 146
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 Source

Here you go:

select length('123-345-566') - length(replace('123-345-566','-',null)) 
from dual;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download