SELECT name,
replace(
replace(
replace(
replace(
replace(
replace(
name,'a',mid('aeiuoy',rand()*5+1,1))
,'e',mid('aeiuoy',rand()*5+1,1))
,'i',mid('aeiuoy',rand()*5+1,1))
,'u',mid('aeiuoy',rand()*5+1,1))
,'o',mid('aeiuoy',rand()*5+1,1))
,'y',mid('aeiuoy',rand()*5+1,1))
as codedname
FROM names;
如果要更随机地替换,应创建如下函数:
CREATE FUNCTION `fReplaceVowels`(s varchar(255)) RETURNS varchar(255) CHARSET latin1
BEGIN
declare v_max int unsigned;
declare v_counter int unsigned default 1;
declare result varchar(255);
set result = s;
set v_max = LENGTH(s);
while v_counter < v_max do
if (select binary 'aeiuoy' like concat('%', mid(s,v_counter,1),'%') ) then
set result=concat(left(result,v_counter-1),mid('aeiuoy',rand()*5+1,1),mid(result,v_counter+1));
end if;
if (select binary 'AEIUOY' like concat('%', mid(s,v_counter,1),'%') ) then
set result=concat(left(result,v_counter-1),mid('AEIUOY',rand()*5+1,1),mid(result,v_counter+1));
end if;
set v_counter=v_counter+1;
end while;
RETURN result;
END
像这样使用:
SELECT name, fReplaceVowels(name) as codedname FROM names;
2条答案
按热度按时间4c8rllxm1#
这不漂亮,但我工作。
如果要更随机地替换,应创建如下函数:
像这样使用:
yhived7q2#
像这样的办法行得通,