Removing Special Characters from Exports
If you need to remove a single special character from an export, such as a phone number, you can use the replace()
function to replace it with nothing.
--Replace % with nothing
replace(@val, '%', '')
What if you need to replace multiple special characters? You can nest multiple replace()
functions:
--Replace + with nothing, then replace - with nothing
replace(replace(@val, '+', ''), '-', '')
However, nesting replace()
a zillion times can become confusing and tedious. Try using translate() to assign all of your special characters to one special character, then replacing just that one.
--Translate a bunch of characters to pipe, then replace pipes with nothing
replace(translate(@val, '!@#$%^&*()', '||||||||||'), '|', '')
string_pattern and string_replacement must be the same length.translate(string_expression, string_pattern, string_replacement)
No Comments