欢迎来到ThinkDifferent的博客

坚持!

(010)每日SQL学习:按字母顺序排列字符串

需求:一串字母'ADFGH',需要按照顺序来显示:A D F G H

第一步:先把字符串拆分

with test as(
select 'ADFGH' as a from dual
)
select a ,substr(a,level,1)
from test
connect by level<=length(a)

第二步:用listagg拼接

with test as(
select 'ADFGH' as a from dual
)
select a ,(select listagg(substr(a,level,1),',') witnin group (order by substr(a,level,1))
from dual
connect by level<=length(a)) b
from test

 

posted @ 2018-01-23 16:38  ThinkDifferent  阅读(493)  评论(0编辑  收藏  举报