How to insert a space after every 3rd character in oracle?

Viewed 23

Say I have a column called FRUITS, ex. “Banana”, “Watermelon”, “pomegranate”

The results I’m looking for are to return

Ban ana Wat erm elo n Pom meg ran ate

1 Answers

Use REGEXP_REPLACE:

SELECT REGEXP_REPLACE(fruits, '(...)', '\1 ') As with_spaces
FROM   table_name

Which, for the sample data:

CREATE TABLE table_name (fruits) AS
SELECT 'Banana' FROM DUAL UNION ALL
SELECT 'Watermelon' FROM DUAL UNION ALL
SELECT 'pomegranate' FROM DUAL

Outputs:

WITH_SPACES
Ban ana
Wat erm elo n
pom egr ana te

fiddle

Related