Sayandip Ghatak
Sayandip Ghatak

Reputation: 303

Put a certain character after every n words in Oracle

I have a sentence like this :

A quick brown fox jumped over the lazy dog

I want to put a comma after every 3 word :

A quick brown , fox jumped over, the lazy dog,

Is it possible using query in Oracle ?

Upvotes: 0

Views: 182

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269563

regexp_replace() would do what you want. Here is one rather simplistic method:

select regexp_replace(s, '([^ ]+[ ]+[^ ]+[ ]+[^ ]+)', '\1,')
from (select 'A quick brown fox jumped over the lazy dog' s from dual) x

Upvotes: 3

Related Questions