Skip to content
Advertisement

How to add a character to specific index in string

I have a db with email-addresses which are 15 characters in total.

Some are 14 characters long and they have the same in common, they miss a 0 in their name at the 3th index.

I had a what similar problem with the id numbers but that was easy to fix because i had to push 0 to the first index.

My expected results should be changing 'aa-001@test.me' to 'aa-0001@test.me'.

Advertisement

Answer

To add a 0 as 4th character in emails having 14 characters, you may simply use SUBSTR :

Another solution is to use REGEXP_REPLACE, with a regular expression that matches only on emails with 14 characters ; this avoids the need for a WHERE clause, as emails that do not match the pattern will be returned untouched :

db<>fiddle here :

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