cnt
is a text column like this:
lorem,ipsum,sky,dolor
lorem,sky,ipsum
lorem,ipsum,dolor,sky
I want to remove sky
from entire column
$sq = "update table set cnt = replace(cnt, :a, :b)";
$st = $db->prepare($sq);
$st->execute([
":a" => 'sky'
":b" => ''
]);
Problemsky
sometimes has a commma - it should be removed also
and sometimes is without comma (at the end of string)
How to remove sky
with and without comma?
UPDATE test
SET cnt = TRIM( BOTH ','
FROM REPLACE(REPLACE(CONCAT(',', cnt, ','),
CONCAT(',', @a, ','),
CONCAT(',', @b, ',')),
',,',
','));
$sq = "update table set cnt = replace(cnt, :a, '')";
$st = $db->prepare($sq);
$st->execute([":a" => $a . ',']);
$st->execute([":a" => $a]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.