将树关系节点名称拼成字符串sql

树自关联表sql,将关系节点名称拼成字符串:

关键字prior :影响最后拼写成的path字符串,放在t.id前,则拼成的串从根->叶。放在t.parentid前,则拼成从叶->根
1.从根往下查
select sys_connect_by_path(t.name, '>>') path form mytable t
 where 1 = 1
 start with t.parentid = 'root'
connect by prior t.id = t.prarentid

2.从子往根查
select sys_connect_by_path(t.name, '>>') path form mytable t
 where 1 = 1
 start with t.isleaf = true
connect by prior t.id = t.prarentid

你可能感兴趣的:(sql)