-1

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
  • 138,499
  • 22
  • 57
  • 95
Bartosz Olchowik
  • 1,129
  • 8
  • 22

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
  • 138,499
  • 22
  • 57
  • 95