The following code will remove the prefix http://wow.example.com
from all rows that match the where clause:
Update `my_table`
set
`my_column` = TRIM(
LEADING 'http://wow.example.com'
FROM `my_column`)
WHERE (`my_column` LIKE '%http://wow.example.com/%');
The next block will remove the suffix index.php
from all entries that match the where clause:
Update `my_table`
set
`my_column` = TRIM(
TRAILING 'index.php'
FROM `my_column`)
WHERE (`my_column` LIKE '%/index.php%');
In case we need to remove the string needle
both from the prefix and the suffix while using a where clause, we can use the following code:
Update `my_table`
set
`my_column` = TRIM(
BOTH 'needle'
FROM `my_column`)
WHERE (`my_column` LIKE '%needle%');
This post is also available in: Αγγλικα