How can I count number of occurrences of the character -
in a varchar2 string?
Example:
select XXX('123-345-566', '-') from dual;
----------------------------------------
2
How can I count number of occurrences of the character -
in a varchar2 string?
Example:
select XXX('123-345-566', '-') from dual;
----------------------------------------
2
Here you go:
Technically, if the string you want to check contains only the character you want to count, the above query will return NULL; the following query will give the correct answer in all cases:
The final 0 in
coalesce
catches the case where you're counting in an empty string (i.e. NULL, because length(NULL) = NULL in ORACLE).Here's an idea: try replacing everything that is not a dash char with empty string. Then count how many dashes remained.
REGEXP_COUNT should do the trick:
here is a solution that will function for both characters and substrings:
where a is the string in which you search the occurrence of b
have a nice day!
I thought of