i want to replace many keywords with only one replace statement in mysql select query.
my table is like
select replace(Text,' ',' ');
i want to replace the matching keywords with concat('_' , Keywords , '__').
Need help.
i want to replace many keywords with only one replace statement in mysql select query.
my table is like
select replace(Text,' ',' ');
i want to replace the matching keywords with concat('_' , Keywords , '__').
Need help.
You can try like this. This can be helpful.
CREATE FUNCTION `SPLIT_STR`(
x text,
delim VARCHAR(12),
pos INT
) RETURNS varchar(255) CHARSET utf8
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
delim, '')
CREATE FUNCTION `GDPR_find_keyword_and_color_them`(qtntext text,keyword nvarchar(50000)) RETURNS text CHARSET utf8
BEGIN
declare ttlkeyword bigint;
declare loopvar bigint;
declare keyword_ nvarchar(1000);
set ttlkeyword=(select count(*) from nsmx_beta4.privacy_policy_keywords);
set loopvar=1;
while(loopvar<ttlkeyword) do
set keyword_=(select SPLIT_STR(keyword,',',loopvar));
if(keyword_!='') then
set qtntext=replace(qtntext,keyword_,concat('<b>',keyword_,'</b>'));
end if;
set loopvar=loopvar+1;
end while;
return qtntext;
END
select GDPR_find_keyword_and_color_them('hello my name is','my,is');
result is : hello my name is