Skip to content
Advertisement

how to count dot number in a string in oracle

I have string like this 125.67.888.66.123. I want to count number of dot operations.

For example:

123.45 => 2

3446.67.88 => 3

23.45.567.88 => 4

I write this query SELECT REGEXP_COUNT ('3.222.123.44.1055', '.') FROM dual;

But it gives 16.How can i obtain 5 for above query.When i find exact number I will start a loop.Do you have any idea?

Advertisement

Answer

You need to escape . — and to add 1:

SELECT REGEXP_COUNT('3.222.123.44.1055', '[.]') + 1
FROM dual; 

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement