replace 3rd and 9th position In a string

Database

replace 3rd and 9th position In a string

Greetings,

I have string (varchar) and I am looking to replace 3rd and 9th position of the string with ‘$’ and ‘#’, on Microsoft SQL Server STUFF function will perform string replacement. Do we have any equivalent functions on Teradata? I gave a try with oreplace,  but it is not handy to identify string postions and substring aslo not helpful.

Example:

Actual string value   = AAABXXCYY  

Expected string value =AA$BXXCY#

 

Best

EP

2 REPLIES
Enthusiast

Re: replace 3rd and 9th position In a string

Ep,

If it's always the third and ninth position in the string, use this...substring(columnname from 1 for 2)||'$'||substring (columnname from 4 for 5)||'#'.

cheers

Enthusiast

Re: replace 3rd and 9th position In a string

REGEX_REPLACE can be used in TD 14 ,if your string is having limited length.But,it may not be suitable for longer fields. substr would be a good option.

Thanks,

Yuva.