I have a table with two fields (countries and ISO codes):
Table1
field1 - e.g. 'Afghanistan' (without quotes)
field2 - e.g. 'AF'(without quotes)
In some rows the second field has whitespace at the start and/or end, which is affecting queries.
Table1
field1 - e.g. 'Afghanistan' (without quotes)
field2 - e.g. ' AF' (without quotes but with that space in front)
Is there a way (in SQL) to go through the table and find/replace the whitespace in field2?
Best Answer
You're looking for TRIM.
Seems like it might be worth it to mention that TRIM can support multiple types of whitespace, but only one at a time and it will use a space by default. You can, however, nest
TRIM
s.If you really want to get rid of all the whitespace in one call, you're better off using
REGEXP_REPLACE
along with the[[:space:]]
notation. Here is an example: