如果需要将查询的某一列相连,这时可能需要用到2个东西:
1.sys_connect_by_path
这个的用法是sys_connect_by_path(需要合并的列名,'分隔符')。
仅仅使用这个是不够的,所以还需要递归查询
2.递归查询
递归查询的简要语法是 select * from ... where ... connect by nocycle prior 递归条件 start with 递归起点条件
nocycle关键字表示递归将忽略递归中产生的死循环
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