0

I have to put a string after every 5 characters in a given string (varchar2). Given string can have different length. I already solved it by a loop using substrings. Is there any way i could reach the goal using REGEXP in Oracle DB?

Nick
  • 118,076
  • 20
  • 42
  • 73
Bartosz Olchowik
  • 269
  • 1
  • 13

1 Answers1

3

You can use REGEXP_REPLACE to replace every 5 characters with those 5 characters followed by another string. For example:

SELECT REGEXP_REPLACE('ABCDE12345FGHIJ67890KL', '(.{5})', '\1*') FROM DUAL

Output:

ABCDE*12345*FGHIJ*67890*KL

Demo on dbfiddle

Nick
  • 118,076
  • 20
  • 42
  • 73