Skip to content
Advertisement

Find the count and indexes of occurrences of a string

Suppose given a string, how can I get the character, no. of occurrences and occurrence indexes in a single query?

Eg : Consultant

Character no of occurrences index:

Advertisement

Answer

You can use a recursive CTE to split it apart and then aggregate:

Here is a db<>fiddle.

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