以下查询显示select *结合connect by并且left join不返回所有列,但仅返回在这些条件中使用的列.这种行为对我很有用,因为select *不应该在发布中使用它,它对请求数据很有用.
with t1 as (
select 1 id, 0 parent, 'ROOT' name from dual
union all
select 2 id, 1 parent, 'CHILD-1' name from dual
union all
select 3 id, 1 parent, 'CHILD-2' name from dual
), t2 as (
select 1 t1id, 'node' special from dual
)
select * from t1
left join t2 on t2.t1id=t1.id
start with id = 2
connect by prior parent = id; …Run Code Online (Sandbox Code Playgroud)