日期:2014-05-16  浏览次数:20534 次

oracle 将查询结果中的一列合并为一个字符串(转)

select max(sys_connect_by_path(username,';')) from?
?? (
?? select?
?????????? u.username,rownum ro?
?? from?
????????? t_base_user u,t_base_role_user ru?
?? where?
???????? u.id = ru.userid
??? ) newtab?
??? start with newtab.ro = 1
??? connect by prior newtab.ro = newtab.ro - 1

?

?注:t_base_user 是用户表 t_base_role_user? 是角色用户关系表

?????????sys_connect_by_path(要合并的列名,分割符)

???????? 查询结果如下:

?????????????????????????????? ;张三;李四;王五

源地址:http://blog.csdn.net/zengzehui/article/details/3405286