假设字符串中只由'A'、'B'、'C'、'D'组成,且长度为7。并设函数REPLICATE(<字符串>,<n>)可以创建一个<字符串>的n个副本的字符串。
另外,还有REPLACE(<目标字符串>,<老字符串>,<新字符串>)。
begin
declare instring char(7);
set instring = 'dcdbaab';
replicate('a', (data_length(instring)-data_length(replace(instring,'a',''))))
||
replicate('b', (data_length(instring)-data_length(replace(instring,'b',''))))
||
replicate('c', (data_length(instring)-data_length(replace(instring,'c',''))))
||
replicate('d', (data_length(instring)-data_length(replace(instring,'d',''))))
end;