SQL对字符串进行排序

假设字符串中只由'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;
上一篇:广度优先算法BFS


下一篇:【转】中间代码opcode的执行