Reputation: 3
I need a query that could remove unnecessary characters (a not-so-needed trailing comma as an example) from the string stored in my database table.
So that
EMAIL_ADD [email protected], [email protected],[email protected], [email protected],
would update it into something like this:
EMAIL_ADD [email protected] [email protected],[email protected] [email protected]
Upvotes: 0
Views: 284
Reputation: 69440
if you only whant to remove the last character of a string you can use
update mytable set my_column = substr(my_column ,0,len(trim(my_column)-1) where mycolumn like '%,'
It is an untested example.
Upvotes: 0
Reputation: 156928
If you have a specific list of characters to filter out at the start and end use trim
functions:
select ltrim(ltrim(rtrim(rtrim(email_add, ','), ' '), ','), ' ')
from tableX
Here I nested ltrim
and rtrim
to remove leading and trailing ,
and .
Or using trim
:
select trim(trim(both ',' from email_add))
from tableX
Upvotes: 0
Reputation: 28741
Using TRIM()
function with TRAILING
option removes a specific unwanted character from end of string , in your case being a comma present at end.
UPDATE tableName
SET EMAIL_ADD = TRIM(TRAILING ',' FROM EMAIL_ADD)
Upvotes: 1